91丨国产丨白浆秘 喷水,国产熟妇毛多 A片欧美蜜臀,北京熟妇搡BBBB搡BBBB,国产精品人人做人人爽人人添

  您的位置: 【卓安特保-您身邊的護(hù)衛(wèi)專家】山東卓安安防工程有限公司,電話13361029977 >> 安防資訊 >> 卓安安防 >> Android編程
 閱讀文章

RelativeLayout(相對(duì)布局)

  文章作者:網(wǎng)絡(luò)來(lái)源:網(wǎng)絡(luò)轉(zhuǎn)摘瀏覽次數(shù):7883字體:字體顏色
 閱讀權(quán)限:游客身份花費(fèi)會(huì)員幣:0添加時(shí)間:2020/4/20 10:04:50提交會(huì)員:李漠

本文摘自:https://www.runoob.com/w3cnote/android-tutorial-relativelayout.html

卓安特保|山東卓安|聯(lián)網(wǎng)報(bào)警|濟(jì)南監(jiān)控安裝|15562629707|13361029977|李田軍

 

本節(jié)引言


LinearLayout是我們用的比較多的一個(gè)布局,我們更多的時(shí)候更鐘情于他的weight(權(quán)重)屬性,等比例劃分,對(duì)屏幕適配還是幫助蠻大的;但是使用LinearLayout的時(shí)候也有一個(gè)問(wèn)題,就是當(dāng)界面比較復(fù)雜的時(shí)候,需要嵌套多層的 LinearLayout,這樣就會(huì)降低UI Render的效率(渲染速度),而且如果是listview或者GridView上的 item,效率會(huì)更低,另外太多層LinearLayout嵌套會(huì)占用更多的系統(tǒng)資源,還有可能引發(fā)stackoverflow; 但是如果我們使用RelativeLayout的話,可能僅僅需要一層就可以完成了,以父容器或者兄弟組件參考+margin +padding就可以設(shè)置組件的顯示位置,是比較方便的!當(dāng)然,也不是絕對(duì)的,具體問(wèn)題具體分析吧! 總結(jié)就是:盡量使用RelativeLayout + LinearLayout的weight屬性搭配使用吧!


1.核心屬性圖


2.父容器定位屬性示意圖


3.根據(jù)兄弟組件定位

恩,先說(shuō)下什么是兄弟組件吧,所謂的兄弟組件就是處于同一層次容器的組件,如圖

圖中的組件1,2就是兄弟組件了,而組件3與組件1或組件2并不是兄弟組件,所以組件3不能通過(guò) 組件1或2來(lái)進(jìn)行定位,比如layout_toleftof = "組件1"這樣是會(huì)報(bào)錯(cuò)的!切記! 關(guān)于這個(gè)兄弟組件定位的最經(jīng)典例子就是"梅花布局"了,下面代碼實(shí)現(xiàn)下:

運(yùn)行效果圖:

實(shí)現(xiàn)代碼:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    
    xmlns:tools="http://schemas.android.com/tools"    
    android:id="@+id/RelativeLayout1"    
    android:layout_width="match_parent"    
    android:layout_height="match_parent" >    
    
    <!-- 這個(gè)是在容器中央的 -->    
        
    <ImageView    
        android:id="@+id/img1"     
        android:layout_width="80dp"    
        android:layout_height="80dp"    
        android:layout_centerInParent="true"    
        android:src="@drawable/pic1"/>    
        
    <!-- 在中間圖片的左邊 -->    
    <ImageView    
        android:id="@+id/img2"     
        android:layout_width="80dp"    
        android:layout_height="80dp"    
        android:layout_toLeftOf="@id/img1"    
        android:layout_centerVertical="true"    
        android:src="@drawable/pic2"/>    
        
    <!-- 在中間圖片的右邊 -->    
    <ImageView    
        android:id="@+id/img3"     
        android:layout_width="80dp"    
        android:layout_height="80dp"    
        android:layout_toRightOf="@id/img1"    
        android:layout_centerVertical="true"    
        android:src="@drawable/pic3"/>    
        
    <!-- 在中間圖片的上面-->    
    <ImageView    
        android:id="@+id/img4"     
        android:layout_width="80dp"    
        android:layout_height="80dp"    
        android:layout_above="@id/img1"    
        android:layout_centerHorizontal="true"    
        android:src="@drawable/pic4"/>    
        
    <!-- 在中間圖片的下面 -->    
    <ImageView    
        android:id="@+id/img5"     
        android:layout_width="80dp"    
        android:layout_height="80dp"    
        android:layout_below="@id/img1"    
        android:layout_centerHorizontal="true"    
        android:src="@drawable/pic5"/>    
    
</RelativeLayout>

4.margin與padding的區(qū)別

初學(xué)者對(duì)于這兩個(gè)屬性可能會(huì)有一點(diǎn)混淆,這里區(qū)分下: 首先margin代表的是偏移,比如marginleft = "5dp"表示組件離容器左邊緣偏移5dp; 而padding代表的則是填充,而填充的對(duì)象針對(duì)的是組件中的元素,比如TextView中的文字 比如為T(mén)extView設(shè)置paddingleft = "5dp",則是在組件里的元素的左邊填充5dp的空間! margin針對(duì)的是容器中的組件,而padding針對(duì)的是組件中的元素,要區(qū)分開(kāi)來(lái)! 下面通過(guò)簡(jiǎn)單的代碼演示兩者的區(qū)別:

比較示例代碼如下:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    
    xmlns:tools="http://schemas.android.com/tools"    
    android:layout_width="match_parent"    
    android:layout_height="match_parent"    
    android:paddingBottom="@dimen/activity_vertical_margin"    
    android:paddingLeft="@dimen/activity_horizontal_margin"    
    android:paddingRight="@dimen/activity_horizontal_margin"    
    android:paddingTop="@dimen/activity_vertical_margin"    
    tools:context=".MainActivity" >    
    
    <Button    
        android:id="@+id/btn1"     
        android:layout_height="wrap_content"    
        android:layout_width="wrap_content"    
        android:text="Button"/>    
    <Button    
        android:paddingLeft="100dp"     
        android:layout_height="wrap_content"    
        android:layout_width="wrap_content"    
        android:text="Button"    
        android:layout_toRightOf="@id/btn1"/>    
        
    <Button    
        android:id="@+id/btn2"     
        android:layout_height="wrap_content"    
        android:layout_width="wrap_content"    
        android:text="Button"    
        android:layout_alignParentBottom="true"/>    
    <Button    
        android:layout_marginLeft="100dp"     
        android:layout_height="wrap_content"    
        android:layout_width="wrap_content"    
        android:text="Button"    
        android:layout_toRightOf="@id/btn2"     
        android:layout_alignParentBottom="true"/>    
        
</RelativeLayout> 

運(yùn)行效果圖比較:


5.很常用的一點(diǎn):margin可以設(shè)置為負(fù)數(shù)

相信很多朋友都不知道一點(diǎn)吧,平時(shí)我們?cè)O(shè)置margin的時(shí)候都習(xí)慣了是正數(shù)的, 其實(shí)是可以用負(fù)數(shù)的,下面寫(xiě)個(gè)簡(jiǎn)單的程序演示下吧,模擬進(jìn)入軟件后,彈出廣告 頁(yè)面的,右上角的cancle按鈕的margin則是使用負(fù)數(shù)的!

效果圖如下:

此處輸入圖片的描述

貼出的廣告Activity的布局代碼吧,當(dāng)然,如果你對(duì)這個(gè)有興趣的話可以下下demo, 因?yàn)閮H僅是實(shí)現(xiàn)效果,所以代碼會(huì)有些粗糙!

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
    xmlns:tools="http://schemas.android.com/tools"  
    android:layout_width="match_parent"  
    android:layout_height="match_parent"  
    tools:context="com.jay.example.relativelayoutdemo.MainActivity"   
    android:background="#00CCCCFF">  
  
    <ImageView  
        android:id="@+id/imgBack"  
        android:layout_width="200dp"  
        android:layout_height="200dp"  
        android:layout_centerInParent="true"  
        android:background="@drawable/myicon" />  
  
    <ImageView  
        android:id="@+id/imgCancle"  
        android:layout_width="28dp"  
        android:layout_height="28dp"  
        android:layout_alignRight="@id/imgBack"  
        android:layout_alignTop="@id/imgBack"  
        android:background="@drawable/cancel"  
        android:layout_marginTop="-15dp"  
        android:layout_marginRight="-10dp" />  
  
</RelativeLayout>  

本節(jié)小結(jié):

關(guān)于RelativeLayout的詳解就到這里,有什么紕漏,錯(cuò)誤,好的建議,歡迎提出~ 最后提供下上面的demo代碼供大家下載:RelativeLayoutDemo

·上篇文章:LinearLayout(線性布局)
·下篇文章:Android系統(tǒng)架構(gòu)
復(fù)制 】 【 打印
 相關(guān)文章
沒(méi)有相關(guān)文章
特別聲明:本站除部分特別聲明禁止轉(zhuǎn)載的專稿外的其他文章可以自由轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處和原始作者。文章版權(quán)歸文章原始作者所有。對(duì)于被本站轉(zhuǎn)載文章的個(gè)人和網(wǎng)站,我們表示深深的謝意。如果本站轉(zhuǎn)載的文章有版權(quán)問(wèn)題請(qǐng)聯(lián)系我們,我們盡快予以更正,謝謝。
關(guān)于我們 | 業(yè)務(wù)范圍 | 免責(zé)聲明 | 聯(lián)系我們 | 友情連接
版權(quán)所有 Copyright © 2007 【卓安特保-您身邊的護(hù)衛(wèi)專家】山東卓安安防工程有限公司,電話13361029977 All Rights Reserved.
魯ICP備11024361號(hào)-5    頁(yè)面執(zhí)行時(shí)間:7.81MS
www.888.www看片| 最爽囗交吞精A片 | 国产成人影视在线观看 | 超碰精品在线观看 | 欧美小嫩槡BBBB槡BBBB搡 | 久久成人免费电影 | 国产精品成人无码一区二区三区 | 欧美成人精品一区二区三区免费 | 美女裸露高潮传媒在线 | 久久一级毛片免费特黄毛片 | 四虎影视8848aamm在线观看 | 国产精品成人免费一区二区视频 | 国产精品爽爽久久久久久 | 免费无码婬片AA片按摩 | 精品人妻一区二区三区四区色欲 | 东北熟女自拍高潮水多 | 麻豆一级A片久久久乱码 | 美女日逼视频污污 | 亚洲AV秘 无码 | 羞羞视频在线观看网站 | 欧美在线视频一区 | 乱码丰满人妻一二三区痴汉电车 | 99国产成人精品 | 97精品欧美91久久久久久久 | 91麻豆精品国产91久久久无限制版 | 中文字幕无码在线 | 狠狠躁夜夜躁人碰人妻视频 | 恃级BBBBBBBBB视频 | 少妇我被躁爽到高潮A片李娜 | 日韩无码中文字幕免费 | 波多野结衣中文一区二区三区0.1 | 精品91 海角乱 | 欧美成人影院一区二区 | 成人黄色A片视频在线观看 国产AⅤ一区仑乱羞羞哒哒 | 无码破解壊版无码网站 | 巨大黑人XXXXX高潮后处理 | 日韩人妻无码精品久久久潘金莲 | 日韩AV在线网站 | 亚洲A片无码一区二区蜜桃 欧美一级婬片AAAA毛片 | 人妻久久久精品69系列A片蜜臀 | 亚洲日韩中文无码 |