Android:带有自定义列表视图的可滚动首选项窗口
我有一个带有列表视图的活动,该列表视图填充了 xml 文件中的首选项,然后是另一个列表视图,该列表视图填充了数据库中的数据,然后是文本视图和编辑文本。
我希望屏幕上的每个元素(包括所有列表视图)都具有完整的高度,并且整个屏幕可以滚动,但我不知道如何做到这一点!
下面是我的 xml:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:fillViewport="true" >
<LinearLayout
android:id="@+id/llContainer"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/llPreferences"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</ListView>
</LinearLayout>
<LinearLayout
android:id="@+id/llPlaces"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="1" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:textAppearance="?android:attr/textAppearanceLarge" >
</TextView>
<ListView
android:id="@+id/lstPlaces"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</ListView>
<LinearLayout
android:id="@+id/llAddNewPlace"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<EditText
android:id="@+id/txtNewPlaceName"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</EditText>
<Button
android:id="@+id/btnAddNewPlace"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add New" >
</Button>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
有什么想法为什么这没有按照我想要的和预期的方式执行吗?
谢谢, 最大限度。
I have an activity with a listview that gets populated with preferences from an xml file, then another listview that gets populated by data in my database, then a textview and a edittext.
I want every element (including all the list views) on the screen to take their full height, and the entire screen be scrollable, but I cannot figure out how to do this!
Below is my xml:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:fillViewport="true" >
<LinearLayout
android:id="@+id/llContainer"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/llPreferences"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</ListView>
</LinearLayout>
<LinearLayout
android:id="@+id/llPlaces"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="1" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:textAppearance="?android:attr/textAppearanceLarge" >
</TextView>
<ListView
android:id="@+id/lstPlaces"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</ListView>
<LinearLayout
android:id="@+id/llAddNewPlace"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<EditText
android:id="@+id/txtNewPlaceName"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</EditText>
<Button
android:id="@+id/btnAddNewPlace"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add New" >
</Button>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
Any ideas why this is not performing as I want and would expect?
Thanks,
Max.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

发布评论
评论(3)
戏蝶舞2024-12-26 11:11:01
此主题的解决方案类似问题:
不幸的是,您似乎无法拥有滚动布局中的列表视图。
对于感兴趣的人来说,现在或将来似乎可以在这里找到潜在的解决方法:
~没有更多了~
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
好吧,首先,确实没有理由将 ListView 封装在线性布局中。事实上,没有理由将任何视图封装在两个 LinearLayout 中。尝试一下,看看会发生什么:
Well, first off, there is really no reason to encapsulate your ListView inside of a Linear Layout inside of a Linear Layout. In fact, there is no reason to encapsulate any of your views inside two LinearLayouts. Try this and see what happens: