【发布时间】:2015-05-14 23:01:50
【问题描述】:
我正在尝试在我的项目中使用 ExpandableListView 和自定义适配器。
ExpandableListView 有我的活动的结果视图:
你怎么看,有些行没有正确的高度,有些行被裁剪了。
我做错了什么?
有我的布局文件
活动布局:
<?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>
【问题讨论】:
-
在第一个 textview 中最高为 20 dp 使其成为 wrap_content
-
将
android:lines=2设置为noticeTitleTextView -
1 - 您可以使用单个 RelativeLayout 而不是 2 个 LinearLayout(更扁平的设计 = 更好的性能)。 2 -
fill_parent已弃用。
标签: android height expandablelistview