我在尝试使某个布局起作用时遇到了一些困难:我想要列表。列表不必是可滚动的,但应该完全显示。但是如果总内容高于屏幕,页面本身应该能够滚动(其中包含列表)。
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linear_layout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#ff181818"
>
<Textview android:id="@+id/my_text" text="header contents goes here" android:layout_width="fill_parent" android:layout_height="wrap_content"/>
<Textview android:id="@+id/headertext" text="header contents goes here" android:layout_width="fill_parent" android:layout_height="wrap_content"/>
<ListView
android:id="@+id/my_list1"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
/>
</LinearLayout>
</ScrollView>
它只使用屏幕的一小部分(每个列表大约 2 行),而不是填充可用高度,并且列表本身可以滚动。如何更改布局以始终显示整个列表但让屏幕滚动?
最佳答案
我使用的解决方案是用LinearLayout替换ListView。您可以在 LinearLayout 中创建所有项目,它们都会显示出来。所以真的没必要用ListView。
LinearLayout list = (LinearLayout)findViewById(R.id.list_recycled_parts);
for (int i=0; i<products.size(); i++) {
Product product = products.get(i);
View vi = inflater.inflate(R.layout.product_item, null);
list.addView(vi);
}
关于android listview显示所有可用项目而无需滚动静态标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1778485/