【问题标题】:Why are some of my views not aligned correctly at the bottom of my relative layout?为什么我的一些视图在相对布局的底部没有正确对齐?
【发布时间】:2019-07-05 03:06:41
【问题描述】:

我的一些视图在列表视图的一行中使用的相对布局中对齐时遇到问题。

这是 Eclipse 中布局构建器的屏幕截图,我认为它应该是这样的:


(来源:janusz.de

下一张图片来自模拟器。现在 TestTestTest 视图位于顶部,涵盖了名称和距离 Textviews。


(来源:janusz.de

这是我的布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:padding="4dip">

<ImageView android:id="@+id/logo" android:layout_width="wrap_content"
    android:layout_height="wrap_content" android:adjustViewBounds="true"
    android:scaleType="centerInside" android:src="@drawable/icon"
    android:layout_centerVertical="true" android:layout_alignParentLeft="true"
    android:background="@color/green" />

<TextView android:id="@+id/distance" android:layout_width="wrap_content"
    android:layout_height="wrap_content" android:text="Distance"
    android:layout_alignParentRight="true" android:layout_alignParentTop="true"
    android:paddingRight="4dip" android:background="#000000" />

<TextView android:id="@+id/name" android:layout_width="fill_parent"
    style="@style/ListHeadText" android:layout_height="wrap_content"
    android:text="Name"
    android:layout_alignTop="@id/distance" android:layout_toRightOf="@id/logo"
    android:layout_toLeftOf="@id/distance" android:gravity="clip_horizontal"
    android:lines="1" android:paddingLeft="4dip" android:background="@color/red" />

<TextView android:id="@+id/number" android:layout_width="wrap_content"
    android:layout_height="wrap_content" android:text="Number"
    android:paddingRight="4dip" android:layout_alignRight="@id/distance"
    android:background="@color/darkred" android:layout_below="@id/distance" />

<TextView android:id="@+id/subcategory" android:layout_width="wrap_content"
    android:layout_height="wrap_content" android:text="Subcategory"
    android:paddingLeft="4dip" android:layout_alignLeft="@id/name"
    android:lines="1" android:gravity="clip_horizontal"
    android:layout_below="@id/distance" android:background="@color/green" />

<TextView android:id="@+id/test" android:layout_width="fill_parent"
    android:layout_height="wrap_content" android:text="TestTestTest"
    android:paddingLeft="4dip" 
    android:layout_alignParentBottom="true" android:gravity="bottom"
    android:background="@color/red" />

不应该 align_parent_bottom 将视图放在列表中单元格的底部吗?

【问题讨论】:

    标签: android layout


    【解决方案1】:

    也尝试添加android:layout_alignParentLeft="true";有时,如果视图不能以至少 2 个点锚定视图,则视图无法正确显示。另外,这是在 ListView 中使用的 RelativeLayout 吗?如果是这样,您可能会发现很难让它看起来正确。有another question 有人遇到了RelativeLayout 本身看起来正确的问题,但一旦它被包含在ListView 中就没有了。我们没能弄清楚出了什么问题,所以他不得不使用嵌套的 LinearLayouts。

    【讨论】:

    • 改为嵌套线性布局。
    猜你喜欢
    • 1970-01-01
    • 2018-05-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-04
    • 2021-06-30
    • 2018-06-04
    • 1970-01-01
    相关资源
    最近更新 更多