日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

Android布局管理器-从实例入手学习相对布局管理器的使用

發布時間:2025/3/19 Android 20 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Android布局管理器-从实例入手学习相对布局管理器的使用 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

場景

AndroidStudio跑起來第一個App時新手遇到的那些坑:

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

使用相對布局RelativeLayout實現簡單的登錄提示的布局,效果如下

?

注:

博客:
https://blog.csdn.net/badao_liumang_qizhi
關注公眾號
霸道的程序猿
獲取編程相關電子書、教程推送與免費下載。

實現

新建之后的默認頁面布局為

?

將其修改為RelativeLayout

?

相對布局只要是要有參照物,即誰在誰下方,誰在誰左邊,和誰左對齊,等等。

首先新建一個TextView,并設置其ID,將其放在屏幕中間

??? <TextViewandroid: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的下方以及在立即更新按鈕的左邊。

??? <Buttonandroid: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"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="發現新的版本,您想現在更新嗎?"android:id="@+id/textView1"android:layout_centerInParent="true"/><Buttonandroid: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"/><Buttonandroid: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>

?

總結

以上是生活随笔為你收集整理的Android布局管理器-从实例入手学习相对布局管理器的使用的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。