android - 将 View 置于 ImageView 的前面 - Android XML

标签 android xml android-layout

我的一个 Activity 的布局有几个问题。这是我目前拥有的:

enter image description here

如您所见,绿色圆圈位于标题图片下方,尽管它应该在顶部重叠。此外,正如您所看到的,圆圈右侧的文本位于标题图像下方,尽管它应该位于下方的一行中。

这是我当前的 XML(我排除了不相关的内容):

<ScrollView
    android:id="@+id/scroll"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:fillViewport="true" >

    <RelativeLayout
        android:id="@+id/container"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="135dp"
            android:id="@+id/headerImageView"
            android:layout_alignParentTop="true"
            android:layout_alignParentStart="true" android:layout_alignParentLeft="true"
            android:scaleType="centerCrop"
            android:adjustViewBounds="false"
            android:background="@drawable/header_image_test" />

        <Button
            android:layout_width="49dp"
            android:layout_height="49dp"
            android:layout_alignBottom="@id/headerImageView"
            android:layout_alignRight="@id/headerImageView"
            android:layout_marginRight="8dp"
            android:layout_marginBottom="8dp"
            android:background="@drawable/star"/>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/headerImageView"
            android:orientation="horizontal"
            android:id="@+id/main_details_layout">

            <TextView
                android:id="@+id/waitTimeTextView"
                android:layout_width="90dp"
                android:layout_height="90dp"
                android:text="@string/wait_time_default"
                android:layout_marginLeft="8dp"
                android:layout_marginRight="16dp"
                android:gravity="center"
                android:background="@drawable/color0"
                android:textColor="#FFFFFF"
                android:layout_marginTop="-30dp"
                android:textSize="30dp" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="60dp"
                android:orientation="vertical">

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="0.7"
                    android:text="Attraction Name"
                    android:textSize="23dp"
                    android:layout_marginRight="8dp"
                    android:gravity="bottom"
                    android:lines="1"
                    android:id="@+id/attractionNameTextView"/>

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:text="Last Updated"
                    android:textSize="16dp"
                    android:layout_marginRight="8dp"
                    android:gravity="bottom"
                    android:id="@+id/updatedTextView"/>
            </LinearLayout>
        </LinearLayout>
    </RelativeLayout>
</ScrollView>

对于文本,我试过强制行数为 1,并专门设置高度,但似乎都没有用。此外,对于圆圈,我曾尝试在代码中将其置于最前面,但它弄乱了布局。

有人对更改有任何建议吗?

最佳答案

您的布局有误。试试这个:

<RelativeLayout
    android:id="@+id/container"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="135dp"
        android:id="@+id/headerImageView"
        android:layout_alignParentTop="true"
        android:layout_alignParentStart="true" android:layout_alignParentLeft="true"
        android:scaleType="centerCrop"
        android:adjustViewBounds="false"
        android:background="@drawable/header_image_test" />

    <Button
        android:layout_width="49dp"
        android:layout_height="49dp"
        android:layout_alignBottom="@id/headerImageView"
        android:layout_alignRight="@id/headerImageView"
        android:layout_marginRight="8dp"
        android:layout_marginBottom="8dp"
        android:background="@drawable/star"/>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/headerImageView"
        android:orientation="horizontal"
        android:layout_marginTop="-30dp"
        android:id="@+id/main_details_layout">

        <TextView
            android:id="@+id/waitTimeTextView"
            android:layout_width="90dp"
            android:layout_height="90dp"
            android:text="@string/wait_time_default"
            android:layout_marginLeft="8dp"
            android:layout_marginRight="16dp"
            android:gravity="center"
            android:background="@drawable/color0"
            android:textColor="#FFFFFF"
            android:textSize="30dp" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="60dp"
            android:layout_marginTop="30dp"
            android:orientation="vertical">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="0.7"
                android:text="Attraction Name"
                android:textSize="23dp"
                android:layout_marginRight="8dp"
                android:gravity="bottom"
                android:lines="1"
                android:id="@+id/attractionNameTextView"/>

            <TextView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:text="Last Updated"
                android:textSize="16dp"
                android:layout_marginRight="8dp"
                android:gravity="bottom"
                android:id="@+id/updatedTextView"/>
        </LinearLayout>
    </LinearLayout>
</RelativeLayout>

关于android - 将 View 置于 ImageView 的前面 - Android XML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35103617/

相关文章:

json - 遍历 XML 节点,然后检查是否有匹配的 json 值,然后选择该值

c# - 在c#中获取具有特定属性值的xml元素

java - 通过蓝牙 Android 传输文件

android - 我需要将广播与警报管理器一起使用吗?

java - 我怎样才能在android中绕过 parent 的属性集给 child

java - 使用 HttpUrlConnection 和 InputStream 下载 PDF 文件

android - 带有按钮的 ListView 项目吞下触摸事件

javascript - iFrame 中的 cordova 回调

java - 检查 xml 元素是否存在的更简单方法

来自代码的 Android 屏幕截图。明白但不完美