2015-05-14 2 views
0

Я пытаюсь использовать ExpandableListView с пользовательским адаптером в моем проекте.Как автоматически установить различную высоту элемента в ExpandableListView?

Существует мнение, результат моей деятельности с ExpandableListView:

enter image description here

Как вы можете видеть, некоторые строки не имеют правильную высоту и некоторые строки обрезаются.

Что я делаю неправильно?

Есть мои файлы разметки

активность раскладка:

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

    <ExpandableListView 
     android:layout_width="matc_parent" 
     android:layout_height="match_parent" 
     android:id="@+id/noticeList"/> 

    <TextView 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content" 
     android:id="@+id/empty" 
     android:text="@string/empty"/> 

</LinearLayout> 

и макет для предмета ExpandableListView:

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

    <ImageView 
     android:layout_width="50dp" 
     android:layout_height="50dp" 
     android:id="@+id/noticeImage"/> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical"> 

     <TextView 
      android:layout_width="fill_parent" 
      android:layout_height="20dp" 
      android:id="@+id/noticeDate"/> 

     <TextView 
      android:layout_height="wrap_content" 
      android:layout_width="fill_parent" 
      android:id="@+id/noticeTitle"/> 

    </LinearLayout> 

</LinearLayout> 
+0

в первом TextView higth составляет 20 дп сделать его wrap_content – Moinkhan

+0

набор 'андроид: строки = 2' для' noticeTitle' TextView – Robust

+0

** 1 ** - Вы можете использовать один RelativeLayout вместо 2 LinearLayouts (более плоский дизайн = лучшие показатели). ** 2 ** - 'fill_parent' устарел. –

ответ

2

Спасибо всем за ответы.

Раствор используют вместо RelativeLayoutLinearLayout:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="horizontal" android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 

    <ImageView 
     android:layout_width="50dp" 
     android:layout_height="50dp" 
     android:id="@+id/noticeImage"/> 



    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_toRightOf="@+id/noticeImage" 
     android:id="@+id/noticeDate" 
     /> 

    <TextView 
     android:layout_height="wrap_content" 
     android:layout_width="match_parent" 
     android:id="@+id/noticeTitle" 
     android:layout_toRightOf="@+id/noticeImage" 
     android:layout_below="@+id/noticeDate" 
     />  
</RelativeLayout> 
0

Попробуйте установить layout_height для TextView noticeDate в wrap_content

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

     <ImageView 
      android:layout_width="50dp" 
      android:layout_height="50dp" 
      android:id="@+id/noticeImage"/> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="vertical"> 

      <TextView 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:id="@+id/noticeDate"/> 

      <TextView 
       android:layout_height="match_parent" 
       android:layout_width="fill_parent" 
       android:id="@+id/noticeTitle"/> 

     </LinearLayout> 

    </LinearLayout> 
+0

Спасибо, но это не работает –

Смежные вопросы