如何将 Button 或 TextView 放在 RelativLayout 的绝对底部?
How can I place Button or TextView at the absolute bottom in RelativLayout?
RelativLayout 中似乎有一些隐藏的填充,对吗?
我有这个 TextView:
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="@color/green"
android:text="LOG IN"/>
在 RelativeLayout 中。
我不明白的是为什么
android:layout_alignParentBottom="true"
不会将 TextView 一直放在下方。
参考图片:
有什么方法可以删除这个填充吗?
我的问题的解决方案非常简单,由@Marco Dufal 提供。
进入 res/values 文件夹中的 dimens.xml 并将边距设置为 0dp:
<dimen name="activity_horizontal_margin">0dp</dimen>
<dimen name="activity_vertical_margin">0dp</dimen>
此处 TextView 的父级是 Entire RelativeLayout。
TextView确实在RelativeLayout的底部,但不代表RelativeLayout的底部与屏幕的绝对底部对齐。
尝试为您的 RelativeLayout 设置 android:layout_marginBottom = "0px"。
顺便说一下,padding 用于 Layout 和它内部的 Views 之间,margin 用于 Layout 和屏幕边框之间的外部
使用此代码,如果您发现任何问题请告诉我...谢谢
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="2dp" >
<ImageView
android:id="@+id/picture"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop" />
<TextView
android:id="@+id/text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/picture"
android:layout_gravity="bottom"
android:background="@drawable/grid_text_back"
android:paddingBottom="15dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="15dp"
android:textColor="@android:color/white"
android:textStyle="bold" />
RelativLayout 中似乎有一些隐藏的填充,对吗?
我有这个 TextView:
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="@color/green"
android:text="LOG IN"/>
在 RelativeLayout 中。
我不明白的是为什么
android:layout_alignParentBottom="true"
不会将 TextView 一直放在下方。 参考图片:
有什么方法可以删除这个填充吗?
我的问题的解决方案非常简单,由@Marco Dufal 提供。
进入 res/values 文件夹中的 dimens.xml 并将边距设置为 0dp:
<dimen name="activity_horizontal_margin">0dp</dimen>
<dimen name="activity_vertical_margin">0dp</dimen>
此处 TextView 的父级是 Entire RelativeLayout。
TextView确实在RelativeLayout的底部,但不代表RelativeLayout的底部与屏幕的绝对底部对齐。
尝试为您的 RelativeLayout 设置 android:layout_marginBottom = "0px"。
顺便说一下,padding 用于 Layout 和它内部的 Views 之间,margin 用于 Layout 和屏幕边框之间的外部
使用此代码,如果您发现任何问题请告诉我...谢谢
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="2dp" >
<ImageView
android:id="@+id/picture"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop" />
<TextView
android:id="@+id/text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/picture"
android:layout_gravity="bottom"
android:background="@drawable/grid_text_back"
android:paddingBottom="15dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="15dp"
android:textColor="@android:color/white"
android:textStyle="bold" />