【发布时间】:2015-06-15 06:59:50
【问题描述】:
我有一个带有三个按钮的线性布局,然后是另一个覆盖先前布局的线性布局。我仍然需要显示第一个布局中的一个按钮。 我怎样才能做到这一点? 到目前为止,这是我的代码:
<?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" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical|center_horizontal|center"
android:layout_marginBottom="10dp"
android:layout_marginLeft="85dp"
android:layout_marginRight="85dp"
android:layout_marginTop="20dp"
android:orientation="vertical"
android:padding="10dp"
android:screenOrientation="portrait" >
<Button
android:id="@+id/fire_help"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="center_vertical|center_horizontal|center"
android:layout_marginBottom="30dp"
android:layout_weight="1"
android:background="@drawable/fire_help"
android:text="@string/fire_service"
android:textColor="@color/White"
android:textStyle="bold" />
<Button
android:id="@+id/police_help"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="center_vertical|center_horizontal|center"
android:layout_marginBottom="30dp"
android:layout_weight="1"
android:background="@drawable/police_help"
android:text="@string/police_help"
android:textColor="@color/White"
android:textStyle="bold" />
<Button
android:id="@+id/medical_help"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="center_vertical|center_horizontal|center"
android:layout_marginBottom="10dp"
android:layout_weight="1"
android:background="@drawable/medical_help"
android:padding="10dp"
android:text="@string/medical_help_description"
android:textColor="@color/White"
android:textStyle="bold"
android:visibility="visible" >
<requestFocus />
</Button>
</LinearLayout>
<LinearLayout
android:id="@+id/overlay"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/overlay_background"
android:clickable="true"
android:orientation="vertical"
android:screenOrientation="portrait"
android:visibility="visible" >
<TableRow
android:id="@+id/textRow1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/overlay_text_background" >
<TextView
android:id="@+id/test_mode"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:gravity="center"
android:padding="20dp"
android:text="@string/test_mode"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@color/White"
android:textSize="25sp"
android:textStyle="bold" />
</TableRow>
<TableRow
android:id="@+id/textRow2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/White" >
<TextView
android:id="@+id/press_button_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="20dp"
android:text="@string/press_button"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="16sp"
android:textStyle="bold" />
</TableRow>
<RelativeLayout
android:id="@+id/overlay_button_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="65dp"
android:layout_marginRight="65dp"
android:layout_marginTop="160dp"
android:layout_marginBottom="20dp"
android:background="@drawable/white_background"
android:orientation="vertical"
android:padding="25dp" >
<Button
android:id="@+id/overlay_medical_help"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/medical_help"
android:padding="10dp"
android:src="@drawable/medical_help"
android:text="@string/medical_help_description"
android:textColor="@color/White"
android:textStyle="bold"
android:visibility="visible" >
<requestFocus />
</Button>
</RelativeLayout>
</LinearLayout>
【问题讨论】:
-
到目前为止你尝试了什么。
-
显示一些代码和你的方法
-
如果可见性消失,您将看不到它。我最好将按钮一劳永逸地插入目标布局中,而不是试图从另一个布局中复制视图。
-
这是一个不同的问题,对于多种屏幕尺寸,您必须采用不同的方法将同名 xml 文件放在不同的 res 文件夹中
标签: android android-layout button