item布局代码如下:<?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"
android:orientation="vertical" >
<TextView android:id="@+id/item_text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:gravity="center"
android:text="测试内容"/></RelativeLayout>效果图如下:这里明明设置了android:layout_marginBottom="10dp",可就是不起作用。至于原因,我想是因为layout_marginBottom这个属性,要是下面没有别的控件,它就不起作用。所以在下面再加一个控件,如下:<?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"
android:orientation="vertical" >
<TextView
android:id="@+id/item_text_view" android:layout_width="match_parent" android:layout_height="wrap_content"
android:layout_marginTop="10dp" android:layout_marginBottom="10dp" android:gravity="center"
android:text="测试内容"/> <View
android:layout_width="match_parent" android:layout_height="0dp" android:layout_below="@id/item_text_view"/></RelativeLayout>效果图如下:这样就实现了想要的效果,至于深层次的原因,有知道的小伙伴可以分享一下,谢谢
ListView的item中RelativeLayout内view的layout_marginBottom无效的问题
最新推荐文章于 2025-01-24 10:28:32 发布