場景
AndroidStudio跑起來第一個App時新手遇到的那些坑:
https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/103797243
使用相對布局RelativeLayout實作簡單的登錄提示的布局,效果如下

注:
博客:
https://blog.csdn.net/badao_liumang_qizhi
關注公眾號
霸道的程式猿
獲取編程相關電子書、教程推送與免費下載,
實作
新建之后的默認頁面布局為

將其修改為RelativeLayout

相對布局只要是要有參照物,即誰在誰下方,誰在誰左邊,和誰左對齊,等等,
首先新建一個TextView,并設定其ID,將其放在螢屏中間
<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>
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/41501.html
標籤:Android
