【发布时间】:2017-07-06 22:40:27
【问题描述】:
您好,我必须使用常规的 Android 布局创建如下所示的 UI(附图片)。我得到了页眉、页脚和中间区域以及图像视图。 根据图片:A区和C区高度相似(屏幕的20%),图像视图应始终放置在B区和C区的中间。
我现在的xml代码是这样的
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<LinearLayout
android:id="@+id/show_contact_bottomArea"
android:layout_width="match_parent"
android:layout_height="120dp"
android:orientation="vertical"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
</LinearLayout>
<LinearLayout
android:id="@+id/show_contact_middleArea"
android:layout_width="match_parent"
android:layout_height="150dp"
android:orientation="vertical"
android:background="@color/grayContact"
android:layout_below="@+id/show_contact_headerArea"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_above="@+id/show_contact_bottomArea">
</LinearLayout>
<LinearLayout
android:id="@+id/show_contact_headerArea"
android:layout_width="match_parent"
android:layout_height="120dp"
android:orientation="vertical"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"></LinearLayout>
<ImageView
android:layout_width="150dp"
android:layout_height="150dp"
app:srcCompat="@drawable/common_google_signin_btn_icon_dark_focused"
android:id="@+id/imageView2"
android:layout_marginBottom="40dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
我给了
marginBottom="40dp"
对于图像视图将其向上推,这不是一个好习惯。将图像视图放置在区域 B 和区域 C 边界中心的最佳方法是什么。
目前我也给了
android:layout_height="120dp"
对于区域 A 和区域 B 的高度,但理想情况下两者都应该是屏幕的 20%(每个),如何实现呢?
【问题讨论】:
-
使用框架布局。它可以灵活地满足这些类型或要求
标签: android android-layout android-relativelayout android-xml