【问题标题】:How can I place Button or TextView at the absolute bottom in RelativLayout?如何将 Button 或 TextView 放置在 RelativeLayout 的绝对底部?
【发布时间】:2015-05-04 23:13:36
【问题描述】:

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"/>

在相对布局中。

我不明白为什么

    android:layout_alignParentBottom="true"

不会将 TextView 一直向下放置。 参考图片:

有什么办法可以去掉这个填充?

【问题讨论】:

  • 尝试检查res/values文件夹下的dimens.xml
  • 非常好。不敢相信我在任何地方都找不到答案
  • 是的,我也遇到了同样的问题...Android Studio 自动生成它...我想您可以通过检查您的布局 xml 来解决...

标签: android xml android-layout textview android-relativelayout


【解决方案1】:

我的问题的解决方案非常简单,由@Marco Dufal 提供。

进入 res/values 文件夹中的 dimens.xml 并将边距设置为 0dp:

<dimen name="activity_horizontal_margin">0dp</dimen>
<dimen name="activity_vertical_margin">0dp</dimen>

【讨论】:

    【解决方案2】:

    这里TextView 的父级是整个RelativeLayout。

    TextView确实在RelativeLayout的Bottom,但并不代表RelativeLayout的底部与屏幕的绝对底部对齐。

    尝试为您的 RelativeLayout 设置 android:layout_marginBottom = "0px"。

    顺便说一句,内边距用于布局和它的内部视图之间,边距用于布局和屏幕边框之间的外部

    【讨论】:

      【解决方案3】:

      使用此代码,如果您发现任何问题,请告诉我...谢谢

      <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" />
      

      【讨论】:

        猜你喜欢
        • 2011-03-30
        • 2017-11-28
        • 1970-01-01
        • 1970-01-01
        • 2016-07-20
        • 1970-01-01
        • 2018-12-30
        • 1970-01-01
        • 2015-09-14
        相关资源
        最近更新 更多