【发布时间】:2018-05-17 16:42:27
【问题描述】:
我想构建以下屏幕,其中包含应用程序徽标、成功/失败图标图像、信息消息和确定按钮。
这是代码。我正在使用线性布局来实现这一点。
<LinearLayout
android:id="@+id/statusLinearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:background="@android:color/white"
android:weightSum="2"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<RelativeLayout
android:id="@+id/statusTopRelativeLayout"
android:background="@android:color/holo_blue_bright"
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical"
android:layout_weight="1">
<ImageView
android:id="@+id/client_logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/no_image_description"
android:src="@drawable/client_logo"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
<RelativeLayout
android:id="@+id/statusBottomRelativeLayout"
android:background="@android:color/holo_blue_light"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<TextView
android:id="@+id/statusText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="50dp"
android:text="@string/statusText"
android:textSize="50sp"/>
<Button
android:id="@+id/btnOk"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/statusText"
android:layout_centerHorizontal="true"
android:layout_marginTop="50dp"
android:clickable="true"
android:focusable="true"
android:onClick="goToHomeScreen"
android:paddingBottom="15dp"
android:paddingTop="15dp"
android:text="@string/ok"
android:textColor="#ffffff"
android:textSize="40sp"/>
</RelativeLayout>
如何在两个布局的顶部放置成功/失败图标图像?
【问题讨论】:
-
在线性(垂直)布局中添加 2 个布局。然后将此线性布局与图像一起添加到RelativeLayout 中。然后将线性布局和图像放在RelativeLayout 的中心。您在 RelativeLayout 中放置项目的顺序关系到哪个项目将位于另一个之上(如 z 轴)。