我的一个 Activity 的布局有几个问题。这是我目前拥有的:
如您所见,绿色圆圈位于标题图片下方,尽管它应该在顶部重叠。此外,正如您所看到的,圆圈右侧的文本位于标题图像下方,尽管它应该位于下方的一行中。
这是我当前的 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/