2010-08-13 7 views
3

상단에 RelativeLayout이 있고 그 아래에 가운데에 ListView가 있으며 마지막으로 하단에 EditText와 Button이있는 또 다른 relativeLayout이 있습니다.키보드가 내 EditText를 숨기는 것을 방지하려면 어떻게해야합니까?

EditText를 클릭하면 IME (가상 키보드)가 표시 될 때 ListView의 크기가 조정되기를 원합니다. 내가 매니 페스트에 adjustResize를 넣으면, IME를위한 공간을 남겨두기 위해리스트 뷰의 크기가 조정되지만 아래의 EditText가있는 RelativeLayout은 IME에 의해 처리되고 내가 쓰고있는 것을 볼 수 없습니다. adjustPan을두면 키보드가 모두 위로 밀리고 ListView의 크기가 조정되지 않고 상단의 RelativeLayout이 풀립니다.

내 코드 : 당신은 명시 적 픽셀 값과의 layout_width와 layout_heights을 설정해서는 안

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:background="@drawable/application_background" 
    android:paddingLeft="15px" 
    android:paddingRight="15px" 
    android:paddingTop="15px" 
    android:paddingBottom="15px"> 

    <RelativeLayout 
     android:id="@+id/rlyParentPost" 
     android:orientation="vertical" 
     android:layout_width="450px" 
     android:layout_height="85px" 
     android:background="@drawable/app_gradient_color" 
     android:layout_centerHorizontal="true"> 
     <ImageView 
      android:id="@+id/imgUserOfParent" 
      android:layout_marginLeft="10px" 
      android:layout_marginTop="10px" 
      android:background="@drawable/userfeed" 
      android:layout_width="64px" 
      android:layout_height="64px" 
      android:layout_below="@+id/logoImg"> 
     </ImageView> 
     <TextView 
      android:layout_below="@+id/logoImg" 
      android:layout_toRightOf="@+id/imgUserOfParent" 
      android:id="@+id/lblNameOfParent" 
      android:textSize="17px" 
      android:textStyle="bold" 
      android:layout_marginLeft="5dip" 
      android:layout_marginTop="11dip" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textColor="#ffffff"> 
     </TextView> 
     <TextView 
      android:layout_below="@+id/lblNameOfParent" 
      android:layout_toRightOf="@+id/imgUserOfParent" 
      android:id="@+id/lblBodyOfParent" 
      android:textColor="#ffffff" 
      android:textSize="17px" 
      android:layout_marginLeft="5dip" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content"> 
     </TextView> 
     <TextView 
      android:layout_below="@+id/lblBodyOfParent" 
      android:layout_toRightOf="@+id/imgUserOfParent" 
      android:id="@+id/lblDateOfParent" 
      android:textColor="#70ccff" 
      android:textSize="11px" 
      android:layout_marginLeft="7dip" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content"> 
     </TextView> 
    </RelativeLayout> 

    <RelativeLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/rlyParentPost" 
     android:id="@+id/contentLayout"> 

    <ListView 
     android:isScrollContainer="true" 
     android:id="@+id/lsvComments" 
     android:layout_height="515px" 
     android:layout_width="450px" 
     android:background="#ffffff" 
     android:listSelector="@drawable/multi_white_color" 
     android:drawSelectorOnTop="false" 
     android:divider="#9aa5ac" 
     android:cacheColorHint="#00000000" 
     android:dividerHeight="1px"> 
    </ListView> 

    <RelativeLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:padding="5dip" 
     android:layout_below="@+id/lsvComments" 
     android:background="@drawable/app_gradient_comments" 
     android:id="@+id/contentLayout"> 
     <EditText 
      android:inputType="text" 
      android:id="@+id/txtComment" 
      android:hint="What are you working on?" 
      android:textSize="22px" 
      android:layout_marginLeft="8px" 
      android:layout_height="72px" 
      android:layout_width="344px"> 
     </EditText> 
     <Button 
      android:layout_toRightOf="@+id/txtComment" 
      android:id="@+id/cmdShare" 
      android:layout_width="79px" 
      android:layout_height="65px" 
      android:background="@drawable/feed_comments_multi_stage" 
      android:layout_marginLeft="7px"> 
     </Button> 
    </RelativeLayout> 
    </RelativeLayout> 
</RelativeLayout> 

답변

2

. 대신 wrap_parent 또는 fill_parent를 적절하게 사용하십시오.

텍스트보기와 같은 모양이 특정 너비가되도록하려면 다른 화면 해상도에서 올바르게 조정할 dpi ​​단위를 사용하십시오.

특정 가상 키보드 문제에 관해서는 나머지 공간을 차지하도록 ListView를 설정하려고합니다. 목록보기 그러나 많은 공간을 차지한다

ListView에 제외한 모든의 높이리스트 뷰가 fill_parent하는 --set 을 wrap_parent하는 --set

,

이 가능하며, 크기를 조정하도록 요청할 때 이렇게 축소.

+0

감사의 말에 의해 Mayra는 당신이 말한 것을 시도했습니다. 나는 fill_parent에 넣은 listview를 제외하고 모두 wrap_content에 넣었습니다. 하지만 활동을 시작할 때 상단의 첫 번째 레이아웃과 아래의리스트 뷰를 모두 보았지만 EditText로 하단 레이아웃을 잃어 버렸기 때문에 edittext를 클릭해도 표시되지 않았습니다. 키보드 – Luciano

+0

레이아웃 참조가 "@ + id"를 사용 중입니다. 무언가가 아래, 다음 등, 다른 것을 지정하면, 상대적인 것으로 설정하는보기가 먼저 와야합니다.그리고 당신은 이미'android : layout_toRightOf = "@ id/txtComment"를 사용하여 선언 된 ID를 주어야합니다. – Falmarri

+0

외부 RelativeLayout을 orientation = "vertical"인 LinearLayout으로 바꿀 수 있어야합니다. 또한 레이아웃 디버깅을위한 좋은 도구는 SDK의 tools 디렉토리에있는 HeirarchyViewer입니다. 레이아웃이 어떻게 생각되는지 시각화합니다. –

2

나는 동일한 문제가있어서 해결책을 찾았습니다. 필자의 경우, Manifeste.xml에서 minSdkVersion = 3 (Android 1.5)을 선언했으며 프로젝트는 Android 2.2 (SDK 8)로 컴파일되었습니다. 이론 상으로는 작동해야하지만 ...! minsdkVersion을 4 (Android 1.6)로 수정했는데 문제가 없습니다. 그것은 다른 안드로이드 SDK 간의 호환성 문제 일뿐입니다. 행운을 빈다.

+0

고마워요! minSdkVersion을 3으로 설정하면 소프트 키보드가 부분적으로 TextEdit 위젯의 하단을 가려 보이지 만 4로 설정하면 고정됩니다. –

+0

우리는 약 2 주 동안이 문제를 가지고있었습니다. –

2

것은 혹시 당신이 사용하는 경우 :

getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); 

이 문제가 발생할 수 있습니다. 원래 상태 표시 줄이 앱을 아래쪽으로 밀어 넣는 버그를 수정하기 위해 해당 행을 추가했으나 키보드가 앱을 위로 밀지 못하게합니다.

한숨.

1

U이 같이있는 ScrollView를 추가 할 수 있습니다 :이 화면에 초점을 편집 텍스트에 초점을 조정하기 위해 응용 프로그램을 야기

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fillViewport="true"> 

.......... 


</ScrollView> 

! 파편 안에서도 작동합니다!

관련 문제