【发布时间】:2015-03-01 20:04:45
【问题描述】:
我正在尝试创建一个包含“两个”ListViews 的视图。 第一个的高度应该等于单个列表项的高度,第二个ListView的高度应该占据剩余空间。
有什么想法吗?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:baselineAligned="false"
android:divider="?android:attr/dividerHorizontal"
android:orientation="vertical" >
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/fragment_forecast"
android:name=MyFragment"
android:layout_width="fill_parent"
android:layout_height="100dp"
tools:layout="@android:layout/list_content" />
<FrameLayout
android:id="@+id/fragment_wear"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
为什么人们是-1这个!!如果你不知道答案,那就直接换一个吧!
【问题讨论】:
-
列表项高度是否可变?
-
@djechelon 更新了我的代码。100dp 是我的问题,我希望它是动态的。
-
如何填充列表?
-
人们对此表示反对,因为您没有说明您为尝试自己解决问题所做的工作。您添加的信息似乎不相关(您添加的 XML 中没有 ListView)并且很难回答您的问题。 re: 怎么计算
my_list_item_height,我问你高度是不是可变的,你说是固定的; 这个固定高度是你应该使用的my_list_item_height -
如果第一个
ListView中所有项目的高度都相同,但由于屏幕分辨率不同,无法提前确定,那么我不认为可以在 xml 中指定 ListView 本身的高度应该等于项目的高度(我可能错了)。您可以做的是在运行时对项目调用layout()和getMeasuredHeight(),并在运行时设置顶部ListView 的高度。所有其他信息,例如第二个 ListView 在第一个之下的事实都可以放在 xml 中。
标签: java android listview layout