黄色网页视频 I 影音先锋日日狠狠久久 I 秋霞午夜毛片 I 秋霞一二三区 I 国产成人片无码视频 I 国产 精品 自在自线 I av免费观看网站 I 日本精品久久久久中文字幕5 I 91看视频 I 看全色黄大色黄女片18 I 精品不卡一区 I 亚洲最新精品 I 欧美 激情 在线 I 人妻少妇精品久久 I 国产99视频精品免费专区 I 欧美影院 I 欧美精品在欧美一区二区少妇 I av大片网站 I 国产精品黄色片 I 888久久 I 狠狠干最新 I 看看黄色一级片 I 黄色精品久久 I 三级av在线 I 69色综合 I 国产日韩欧美91 I 亚洲精品偷拍 I 激情小说亚洲图片 I 久久国产视频精品 I 国产综合精品一区二区三区 I 色婷婷国产 I 最新成人av在线 I 国产私拍精品 I 日韩成人影音 I 日日夜夜天天综合

android LinearLayout和RelativeLayout實現精確

系統 2501 0
先明確幾個概念的區別:
padding margin:都是邊距的含義,關鍵問題得明白是什么相對什么的邊距
padding:是控件的內容相對控件的邊緣的邊距.

margin :是控件邊緣相對父空間的邊距

android LinearLayout和RelativeLayout實現精確布局


android:gravity 是對該view 內容的限定.

比如一個button 上面的text. 你可以設置該text 在view的靠左,靠右等位置.該屬性就干了這個.

android:layout_gravity 是用來設置該view中的子view相對于父view的位置.

比如一個button 在linearlayout里,你想把該button放在靠左,靠右等位置就可以在linearlayout中通過該屬性設置


XML 布局文件

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
	android:orientation="horizontal" 
	android:layout_width="fill_parent"
	android:layout_height="wrap_content" 
	android:gravity="center_vertical">
	
	<ImageView android:id="@+id/ivLogo" 
		android:layout_width="50dp"
		android:layout_height="50dp" 
		android:src="@drawable/icon"
		android:paddingLeft="5dp" />
		
	<RelativeLayout android:id="@+id/rl_name"
		android:layout_width="wrap_content" 
		android:layout_height="wrap_content"
		android:gravity="right" 
		android:padding="10dp">
		
		<TextView android:id="@+id/tvApplicationName"
			android:layout_width="wrap_content" 
			android:layout_height="wrap_content"
			android:textSize="16dp" />
	</RelativeLayout>
	
	<RelativeLayout android:id="@+id/rl_score"
		android:layout_width="fill_parent" 
		android:layout_height="wrap_content"
		android:gravity="right" 
		android:padding="10dp">
		
		<TextView android:id="@+id/tvRating" 
		android:layout_width="wrap_content"
			android:layout_height="wrap_content" 
			android:text="5.0" />
			
		<RatingBar android:id="@+id/ratingbar" 
			android:layout_width="wrap_content"
			android:layout_height="wrap_content" 
			android:numStars="5"
			style="?android:attr/ratingBarStyleSmall" 
			android:layout_below="@id/tvRating" />
	</RelativeLayout>
	
</LinearLayout>

  

上面布局文件的效果圖

android LinearLayout和RelativeLayout實現精確布局


上面的布局文件是一個ListView中的list_item布局,在一個ListView中顯示所有的APK資源,每個資源項顯示圖標,名稱及評分。

在listItem的最外層LinearLayout中加 android:gravity="center_vertical" ,設定內容垂直居中顯示。

在id為 rl_score 的RelativeLayout中設定 android:layout_width="fill_parent" 來填充剩余空間;

android:gravity="right" 設定內容相對于 rl_score 右對齊;

android:padding="10dp" 設定RelativeLayout中的內容相對RelativeLayout的邊緣的邊距為10dp。
這個布局雖然簡單,但卻是經常用到的。


android LinearLayout和RelativeLayout實現精確布局


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論