2016-08-22 1 views
-1

레이아웃에 두 개의 ListView를 추가했습니다. 나는 그들이 활동 전반에 걸쳐 그들의 layout_weight를 유지하기를 원한다. 하지만 두 번째 ListView 항목을 추가 할 때 첫 번째 할당 된 layout_weight 무시하고 축소합니다. 어떻게이 문제를 해결할 수 있습니까? 단일 레이아웃의 두 ListViews는 목록 항목을 추가 한 후에 가중치를 변경합니다.

그리고 여기에 코드입니다 : 여기

내가 기대하는 것입니다

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/content_add_group_members_layout" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="3" 
     android:orientation="vertical"> 

     <TextView 
      android:id="@+id/content_add_group_text_name" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="First List" /> 

     <View 
      android:layout_width="match_parent" 
      android:layout_height="1dp" 
      android:background="#DDD" /> 

     <FrameLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"> 

      <ListView 
       android:id="@+id/list_added_people" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" /> 

      <TextView 
       android:id="@+id/added_people_empty_view" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:text="List One Empty View"/> 

     </FrameLayout> 

    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="7" 
     android:orientation="vertical"> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="Second List" /> 

     <View 
      android:layout_width="match_parent" 
      android:layout_height="1dp" 
      android:background="#DDD" /> 

     <FrameLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"> 

      <ListView 
       android:id="@+id/list_contacts" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:clipToPadding="false" /> 

      <TextView 
       android:id="@+id/contacts_empty_view" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:text="List Two Empty View"/> 

      <com.github.silvestrpredko.dotprogressbar.DotProgressBar 
       android:id="@+id/dots" 
       android:layout_width="wrap_content" 
       android:layout_height="16dp" 
       android:layout_gravity="center" 
       android:visibility="gone" /> 

     </FrameLayout> 

    </LinearLayout> 

</LinearLayout> 
+1

루트'LinearLayout'의'layout_height'는'match_parent'이어야합니다. 그것도'FrameLayout'과'ListView' 두 가지 모두에 해당됩니다. –

+0

그것으로 해결됩니다 @MikeM !! 문제가 무엇인지 설명해 주시겠습니까? –

+0

'ListView'의 높이에'wrap_content'를 사용하고 싶지는 않지만 루트 문제의 주된 문제는'LinearLayout' 루트의'wrap_content' 였을 것입니다. 감싸기 위해서는 자녀의 몸무게를 알아야하지만, 몸무게를 사용하여 자녀의 몸무게를 계산할 때 자신의 몸무게를 알아야합니다. 그 원형 종속성은 첫 번째 그룹의 자녀들의 부정확 한 높이와 함께 예기치 않은 행동으로 이어지고있었습니다. –

답변

1

아래의 코드가 그 두 차일에 android:layout_weight="1"를 부모 레이아웃에 android:weightSum="2"을 추가하고 설정하십시오 공백.

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/content_add_group_members_layout" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    android:weightSum="2"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:orientation="vertical"> 

     <TextView 
      android:id="@+id/content_add_group_text_name" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="First List" /> 

     <View 
      android:layout_width="match_parent" 
      android:layout_height="1dp" 
      android:background="#DDD" /> 

     <FrameLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"> 

      <ListView 
       android:id="@+id/list_added_people" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" /> 

      <TextView 
       android:id="@+id/added_people_empty_view" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:text="List One Empty View" /> 

     </FrameLayout> 

    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:orientation="vertical"> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="Second List" /> 

     <View 
      android:layout_width="match_parent" 
      android:layout_height="1dp" 
      android:background="#DDD" /> 

     <FrameLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"> 

      <ListView 
       android:id="@+id/list_contacts" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:clipToPadding="false" /> 

      <TextView 
       android:id="@+id/contacts_empty_view" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:text="List Two Empty View" /> 

      <com.github.silvestrpredko.dotprogressbar.DotProgressBar 
       android:id="@+id/dots" 
       android:layout_width="wrap_content" 
       android:layout_height="16dp" 
       android:layout_gravity="center" 
       android:visibility="gone" /> 

     </FrameLayout> 

    </LinearLayout> 

</LinearLayout> 
+0

@ alpha-rion 문제가 해결되었습니다. –

+0

예, MikeM의 의견에서 Mike가 제안한대로 가중치를 변경하지 않았지만 레이아웃 매개 변수를 변경했습니다. –