如何在一个视图之上创建一个视图?
How to create a view on top of one view?
我正在创建一个简单的 android 应用程序。对于我的登录页面,我想在它的顶部有一个背景图片和另一个视图,就像我下面的示例一样(想象一下黑色部分是我的背景图片,绿色部分是带有描述和两个按钮的视图!)对现在我将背景图片设置为我的相对布局 activity 并且我正在使用我正在谈论的视图的警报对话框!
我想知道有没有更好更简洁的方法来做到这一点?因为有了警报对话框,我需要处理很多情况!
非常感谢
我建议您将 activity 的相对布局更改为线性布局(具有垂直方向属性),然后将图像和登录面板添加到其中。
通过这种方式,您可以像行一样排列视图!
下面是一个简单的 xml 示例:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
inser the image view ..
insert the login pannel
</LinearLayout>
试试这个,
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#00FF00"
android:layout_margin="16dp" >
<TextView
android:id="@+id/description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Description"
android:padding="16dp"
android:textColor="#FFFFFF" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/description"
android:orientation="horizontal"
android:weightSum="2" >
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="bottom"
android:padding="16dp"
android:text="Button1" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="16dp"
android:text="Button2" />
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
我正在创建一个简单的 android 应用程序。对于我的登录页面,我想在它的顶部有一个背景图片和另一个视图,就像我下面的示例一样(想象一下黑色部分是我的背景图片,绿色部分是带有描述和两个按钮的视图!)对现在我将背景图片设置为我的相对布局 activity 并且我正在使用我正在谈论的视图的警报对话框!
我想知道有没有更好更简洁的方法来做到这一点?因为有了警报对话框,我需要处理很多情况!
非常感谢
我建议您将 activity 的相对布局更改为线性布局(具有垂直方向属性),然后将图像和登录面板添加到其中。 通过这种方式,您可以像行一样排列视图! 下面是一个简单的 xml 示例:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
inser the image view ..
insert the login pannel
</LinearLayout>
试试这个,
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#00FF00"
android:layout_margin="16dp" >
<TextView
android:id="@+id/description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Description"
android:padding="16dp"
android:textColor="#FFFFFF" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/description"
android:orientation="horizontal"
android:weightSum="2" >
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="bottom"
android:padding="16dp"
android:text="Button1" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="16dp"
android:text="Button2" />
</LinearLayout>
</RelativeLayout>
</RelativeLayout>