带 ListView 的相对布局未正确显示
我正在疯狂地尝试使相对布局发挥作用。我遇到了 ListView 的问题,listView 总是显示一个空白空间,大约是一个 listView 元素高度的两倍,如果列表足够大以滚动或不滚动,则独立(通常列表容纳 4 个元素而不需要滚动) 。
为了解决这个问题,我正在尝试实现一个RelativeLayout。我的顶部有一个 TextView,底部有一个,我的列表视图位于中间。 textView 必须“粘合”在我的列表视图上,在出现空白问题之前我使用的是 LinearLayout,现在我有这个相对布局:
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@drawable/background"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:orientation="vertical"
android:layout_height="fill_parent">
...
<RelativeLayout android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="@+datatrade/tv_itens"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:text="Itens:" />
<TextView
android:id="@+datatrade/tv_value"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Value:" />
<ListView android:layout_width="fill_parent"
android:layout_height="200px"
android:layout_below="@datatrade/tv_itens"
android:layout_above="@datatrade/tv_value"
android:id="@+id/list_product"
/>
</RelativeLayout>
...
问题是,我刚刚显示了第二个文本视图,其中包含“值:”,并且没有别的了! 所有其余的相对布局都会被 android 忽略!
有谁知道可能是什么问题?
I'm going crazy trying to make an relative layout work. I was getting an problem with ListView, the listView always show an empty space with approximately, twice the height of one listView element, independent if the list is big enough to scroll or not (usually the list accommodate 4 elements without the need of scroll).
To solve that, I'm trying to implement an RelativeLayout. I have One TextView at the top, and one at the bottom, and my listview is in the middle. The textView's must be "glued" on my listview, I was using LinearLayout before the empty space problem, and now I have this Relative Layout:
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@drawable/background"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:orientation="vertical"
android:layout_height="fill_parent">
...
<RelativeLayout android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="@+datatrade/tv_itens"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:text="Itens:" />
<TextView
android:id="@+datatrade/tv_value"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Value:" />
<ListView android:layout_width="fill_parent"
android:layout_height="200px"
android:layout_below="@datatrade/tv_itens"
android:layout_above="@datatrade/tv_value"
android:id="@+id/list_product"
/>
</RelativeLayout>
...
The problem is, that I just get my second text view shown, with "values: ", and nothing else!
All the rest of the relative layout is just ignored by android!
Does anyone know what can be the problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您尚未声明此文本视图应显示在何处。
you have not declared where this textview should be displayed.
您必须指定每个对象彼此相关。否则,相对布局无法理解您将对象放置在哪里,并且不会有相关性。
检查此项以了解对象之间的相对性以及如何放置它们
You have to specify each object to be related to each other.Otherwise there is no way that relative layout would understand where you position the object and there will be no relativity.
Check this to understand the relativity between objects and how to position them
试试这个:
您需要告诉 ListView 位于第一个 TextView 下方,然后告诉第二个 TextView 位于 ListView 下方。
另外你的id看起来有点奇怪,当我复制你的代码时我收到了警告,请尝试使用@+id来确定。
最后,您不应该使用 px 作为尺寸,而应使用相对的 dp 。
Try this:
You need to tell the ListView to be below the first TextView and then the second TextView to be below the ListView.
Also your id's seem a bit wierd, I got a warning when I copied your code, try using @+id to be sure.
Finally you shouldn't use px as a size, instead use dp which is relative.