Android Layout Manager - to start learning from the relative layout manager instance

Scenes

AndroidStudio run up those pits when the first App novice encountered:

https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/103797243

RelativeLayout layout using relatively simple layout of the login prompt, the effect is as follows

 

 

Note:

Blog:
https://blog.csdn.net/badao_liumang_qizhi
public concern number of
programs overbearing ape
acquisition-related programming e-books, tutorials and push for free download.

achieve

After the default page layout for the new

 

 

Be amended to RelativeLayout

 

 

As long as the relative layout is to have a reference, that is, who in the bottom who, left who is who, and who is left-aligned, and so on.

First create a TextView, and set its ID, which is the middle of the screen

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="发现新的版本,您想现在更新吗?"
        android:id="@+id/textView1"
        android:layout_centerInParent="true"/>

 

主要通过  android:layout_centerInParent="true"/> 设置在中间。

然后将现在更新按钮通过android:layout_below="@+id/textView1"设置位于TextView的下方,通过android:layout_alignRight="@+id/textView1"/>设置与TextView右对齐。

然后再添加一个按钮使其在textView的下方以及在立即更新按钮的左边。

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="现在更新"
        android:id="@+id/button2"
        android:layout_below="@+id/textView1"
        android:layout_toLeftOf="@+id/button1"/>

 

完整示例代码

<?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"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="发现新的版本,您想现在更新吗?"
        android:id="@+id/textView1"
        android:layout_centerInParent="true"/>


    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="以后再说"
        android:id="@+id/button1"
        android:layout_below="@+id/textView1"
        android:layout_alignRight="@+id/textView1"/>

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="现在更新"
        android:id="@+id/button2"
        android:layout_below="@+id/textView1"
        android:layout_toLeftOf="@+id/button1"/>

</RelativeLayout> 

Guess you like

Origin www.cnblogs.com/badaoliumangqizhi/p/12150786.html