我试图将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.
更多推荐
发布评论