Android ListView 未按预期扩展
我的情况是这样的:
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="vertical"
android:background="#ffffeb">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp">
// Other stuff in between here..
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="12dp"
android:paddingRight="12dp">
<Button
android:id="@+id/insert_ad_ad_information_category_and_type_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:text="@string/insert_ad_ad_information_category_and_type_button"/>
<ListView
android:id="@+id/insert_ad_ad_information_parameters_frame"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffeb"
android:cacheColorHint="#00000000"
android:divider="#00000000"
android:dividerHeight="0dp"
android:scrollbars="none"
android:listSelector="@android:color/transparent"/>
我遇到的问题是我无法让我的 ListView
获得我想要的正确高度。
我将使用自定义 BaseAdapter
类添加几个组件,其中的所有内容都会按预期工作。
但是,当我调试应用程序时,我只能在列表中看到 3 个组件中的 1.5 个,其余的则隐藏在 ListView
中。
但是我怎样才能让我的 ListView
计算我有多少个组件并让它直接显示我的所有组件而无需向下滚动呢?
另一个想法是我是否可以使用我的 BaseAdapter
填充任何其他类型的视图?因为我使用 ListView
的唯一原因是 setAdapter()
方法。
感谢所有的想法和评论:)
My scenario is like this:
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="vertical"
android:background="#ffffeb">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp">
// Other stuff in between here..
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="12dp"
android:paddingRight="12dp">
<Button
android:id="@+id/insert_ad_ad_information_category_and_type_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:text="@string/insert_ad_ad_information_category_and_type_button"/>
<ListView
android:id="@+id/insert_ad_ad_information_parameters_frame"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffeb"
android:cacheColorHint="#00000000"
android:divider="#00000000"
android:dividerHeight="0dp"
android:scrollbars="none"
android:listSelector="@android:color/transparent"/>
The problem I have is that I can't get my ListView
to get the right height that I want.
I'll add a couple of components with my custom BaseAdapter
class and everything there works as intended.
But when I then debug my application I can only see 1,5 out of 3 components in the list and the rest is hidden further down in the ListView
.
But how can I make my ListView
calculate how many components I have and get it to show all my components directly without having too scroll down?
Another thought is if I could populate any other kind of View with my BaseAdapter
? Because the only reason I am using ListView
is because of the setAdapter()
method.
Appreciate all thoughts and comments :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
ScrollView 中不能有 ListView。这就是问题所在。
You cannot have a ListView in a ScrollView. Thats where the issue is.
正如已经说过的,你不能在 ScrollView 中使用 ListView。
如果您希望列表视图具有不同类型的项目并滚动那些具有“普通”项目的项目
事实上你确实需要定制适配器。如果您愿意,您可以将其基于 BaseAdapter
适配器必须支持您的项目类型,并扩展适当的布局,
As has been said you can't use ListView inside ScrollView.
If you want your listview have different types of items and scroll those with "normal" items
you do in fact need custom adapter. You can base it on BaseAdapter if you like
Adapter has to support your item types, and inflate appropriate layouts,