解决android:layout_marginBottom在RelativeLayout中无效的bug
16lz
2021-01-26
原xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <ImageView android:id="@+id/iv" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="15dp"/> RelativeLayout>
以上代码中android:layout_marginBottom=”15dp”是没有作用的,原因是在ImageView下,已经没有任何View了,所以导致了android:layout_marginBottom失效了。
解决方法:
在ImageView底部加入一个空的View,然后设置ImageView在此View之上即可。
代码如下:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <ImageView android:id="@+id/iv" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@+id/view_none" android:layout_marginBottom="15dp"/> <View android:id="@+id/view_none" android:layout_width="0px" android:layout_height="0px" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" /> RelativeLayout>
更多相关文章
- android2.2 2.3状态栏区别
- Android第三方文件选择器aFileChooser使用方法详解
- 实现Android多张图片选择
- Android(安卓)Studio常用快捷键、Android(安卓)Studio快捷键大全
- android studio常用快捷键整理
- Android代码内存优化建议-Android官方篇
- android数据库——SQLiteDatabase的Helper类
- Bluetooth in Android(安卓)4.2 and 4.3(一):综述
- Android(安卓)Canvas练习(8)自已绘环形图(Dount Chart)