Android ListView重叠(Android ListView overlapping)

编程入门 行业动态 更新时间:2024-10-25 14:32:12
Android ListView重叠(Android ListView overlapping)

我试图将LinearLayout设置在ListView下面,这很长,所以ListView与下面的布局重叠。我尝试了几种方法,有时它在预览中看起来不错,但在运行时不在模拟器中。 到目前为止,这是我的简单布局(还有其他一些,也没有用)。 我生气地被这个可怜的问题困扰了。 有人可以解决我的谜题吗?

<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:id="@+id/footer" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center"> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="send" android:text="@string/odeslat" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="reset" android:text="@string/reset" /> </LinearLayout> <RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@id/footer"> <ListView android:id="@+id/questionlst" android:layout_width="fill_parent" android:layout_height="fill_parent" /> </RelativeLayout> </RelativeLayout>

Im trying to have LinearLayout below a ListView, which is pretty long, so the ListView is overlapping the layout below.. I have tried several ways, sometimes it looks good in the preview, but not in the emulator at runtime. This is my simple layout so far (had several others, that didnt work as well). Im getting mad to be stucked with this poor problem. Can anyone solve my puzzle please?

<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:id="@+id/footer" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center"> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="send" android:text="@string/odeslat" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="reset" android:text="@string/reset" /> </LinearLayout> <RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@id/footer"> <ListView android:id="@+id/questionlst" android:layout_width="fill_parent" android:layout_height="fill_parent" /> </RelativeLayout> </RelativeLayout>

最满意答案

您只需要将android:layout_alignParentBottom="true"到页脚LinearLayout 。 而已! 你得到这样的东西:

<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:id="@+id/footer" android:layout_alignParentBottom="true" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center"> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="send" android:text="hey" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="reset" android:text="hey" /> </LinearLayout> <ListView android:id="@+id/questionlst" android:layout_above="@id/footer" android:layout_width="match_parent" android:layout_height="match_parent" />

刚检查过,它可以在Android Studio中运行。

You just needed to add android:layout_alignParentBottom="true" to your footer LinearLayout. That's it! You get something like this:

<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:id="@+id/footer" android:layout_alignParentBottom="true" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center"> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="send" android:text="hey" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="reset" android:text="hey" /> </LinearLayout> <ListView android:id="@+id/questionlst" android:layout_above="@id/footer" android:layout_width="match_parent" android:layout_height="match_parent" />

Just checked it, it works in Android Studio.

更多推荐

本文发布于:2023-08-08 01:31:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1466744.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Android   ListView   overlapping

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!