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

歡迎訪問 生活随笔!

生活随笔

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

Android

.Net程序猿玩转Android开发---(7)相对布局RelativeLayout

發布時間:2025/3/21 Android 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 .Net程序猿玩转Android开发---(7)相对布局RelativeLayout 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
?????????? ? 相對布局RelativeLayout是Android布局中一個比較經常使用的控件,使用該控件能夠布局出適合各種屏幕分辨率的布局,RelativeLayout採用相對位置進行控件屬性設置.

能夠設置控件與父控件的位置,控件與控件之間的位置。

?????????????? 1. 控件與父容器位置屬性

?????????????????????????????? ? android:layout_alignParentLeft="true"?? 子控件相對于父容器靠左邊
???????????????????????????????? android:layout_alignParentTop="true"??? 子控件相對于父容器靠 上邊
?????????????????????????????????android:layout_marginTop="50dp"????????? 子控件與父容器上邊距距離
??????????????????????????????? android:layout_marginBottom="50dp"??? 子控件與父容器下邊距距離
??????????????????????????????? android:layout_marginRight="50dp"????? 子控件與父容器右邊距距離
???????????????????????????????? android:layout_marginLeft="50dp"????? 子控件與父容器左邊距距離

?????????????????????????????????? ?? android:layout_centerInParent="true"//子控件在父容器中居中顯示
???????????????????????????????? ? ?android:layout_centerHorizontal="true"?//子控件在父容器中水平居中
???????????????????????????????????? android:layout_centerVertical="true"? 子控件在父容器中垂直居中

?????????????????????????? 以下的演示樣例展示下相對于父容器的布局

????????????????????????????

???????????????????????

<?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" ><TextViewandroid:id="@+id/textView1"android:layout_width="match_parent"android:layout_height="match_parent"android:text="相對父easy布局" android:background="#97FFFF"android:layout_alignParentLeft="true"android:layout_alignParentTop="true"android:layout_marginTop="50dp"android:layout_marginBottom="50dp"android:layout_marginRight="50dp"/></RelativeLayout>

?????????????? 2.控件與控件間位置屬性

?????????????????????控件與控件之間的位置屬性,是指控件與相鄰控件的位置設置,主要有下面屬性

?????????????????????? android:layout_below="@+id/textView1"??? 該控件位于指定控件的下方
????????????????? ??? android:layout_toLeftOf="@+id/textView1"??? 控件位于指定控件的左側
???????????????????? ?android:layout_toRightOf="@+id/textView1"??? 控件位于指定控件的右側
??????????????????? ?android:layout_above="@+id/textView1"?????????? 控件位于指定控件的上面
???????????????????? android:layout_alignBaseline="" 該控件的內容與指定控件的內容在同一直線上

??????????????????? android:layout_alignBottom=""該控件的底部與指定控件的底部對齊

????????????????? ? android:layout_alignLeft="" 該控件與指定控件左側對齊

????????????????? ? android:layout_alignRight="" 該控件與指定控件右側對齊

??????????????????? android:layout_alignTop="" 該控件與指定控件的頂部對齊

???????????????????????

???????????????????????

<?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:gravity="center" ><RelativeLayoutandroid:layout_width="match_parent"android:layout_height="110dp" android:id="@+id/layone"><TextViewandroid:id="@+id/textView1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:background="#FFD700"android:text="標簽1" /><TextViewandroid:id="@+id/textView2"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_below="@+id/textView1"android:background="#FF0000"android:text="標簽2" /></RelativeLayout><RelativeLayoutandroid:layout_width="match_parent"android:layout_height="120dp"android:layout_below="@+id/layone"><TextViewandroid:id="@+id/textView3"android:layout_width="wrap_content"android:layout_height="wrap_content"android:background="#EE9572"android:text="標簽3" /><TextViewandroid:id="@+id/textView4"android:layout_width="wrap_content"android:layout_height="60dp"android:layout_toRightOf="@+id/textView3"android:background="#CDAA7D"android:text="標簽4" /></RelativeLayout></RelativeLayout>

?????????????? 3.商品列表演示樣例

以下我們展示一個商品列表,使用RelativeLayout來展示,效果圖例如以下 ????????????????????? 代碼 <?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" ><RelativeLayoutandroid:layout_width="match_parent"android:layout_height="120dp"android:id="@+id/layout1"><ImageViewandroid:id="@+id/imageView1"android:layout_width="100dp"android:layout_height="wrap_content"android:layout_alignParentLeft="true"android:layout_alignParentTop="true"android:layout_marginLeft="10dp"android:layout_marginTop="10dp"android:src="@raw/pad" /><TextViewandroid:id="@+id/textView1"android:layout_width="fill_parent"android:layout_height="wrap_content"android:layout_alignTop="@+id/imageView1"android:layout_marginTop="10dp"android:layout_toRightOf="@+id/imageView1"android:text="商品名稱:IPAD AIR" /><TextViewandroid:id="@+id/textView2"android:layout_width="fill_parent"android:layout_height="wrap_content"android:layout_marginTop="10dp"android:layout_toRightOf="@+id/imageView1"android:layout_below="@+id/textView1"android:text="商品價格:$19" /><TextViewandroid:id="@+id/textView3"android:layout_width="fill_parent"android:layout_height="wrap_content"android:layout_marginTop="10dp"android:layout_toRightOf="@+id/imageView1"android:layout_below="@+id/textView2"android:text="商品顏色:白色" /></RelativeLayout><RelativeLayoutandroid:layout_width="match_parent"android:layout_height="3dp"android:background="#CDAA7D"android:layout_below="@+id/layout1"android:id="@+id/layout2"></RelativeLayout><RelativeLayoutandroid:layout_width="match_parent"android:layout_height="120dp"android:layout_below="@+id/layout2"android:id="@+id/layout3"><ImageViewandroid:id="@+id/imageView2"android:layout_width="100dp"android:layout_height="wrap_content"android:layout_alignParentLeft="true"android:layout_alignParentTop="true"android:layout_marginLeft="10dp"android:layout_marginTop="10dp"android:src="@raw/pad" /><TextViewandroid:id="@+id/textView4"android:layout_width="fill_parent"android:layout_height="wrap_content"android:layout_alignTop="@+id/imageView2"android:layout_marginTop="10dp"android:layout_toRightOf="@+id/imageView2"android:text="商品名稱:IPAD AIR" /><TextViewandroid:id="@+id/textView5"android:layout_width="fill_parent"android:layout_height="wrap_content"android:layout_marginTop="10dp"android:layout_toRightOf="@+id/imageView2"android:layout_below="@+id/textView4"android:text="商品價格:$19" /><TextViewandroid:id="@+id/textView6"android:layout_width="fill_parent"android:layout_height="wrap_content"android:layout_marginTop="10dp"android:layout_toRightOf="@+id/imageView2"android:layout_below="@+id/textView5"android:text="商品顏色:白色" /></RelativeLayout><RelativeLayoutandroid:layout_width="match_parent"android:layout_height="3dp"android:background="#CDAA7D"android:layout_below="@+id/layout3"></RelativeLayout></RelativeLayout>
  

總結

以上是生活随笔為你收集整理的.Net程序猿玩转Android开发---(7)相对布局RelativeLayout的全部內容,希望文章能夠幫你解決所遇到的問題。

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