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

歡迎訪問 生活随笔!

生活随笔

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

Android

Android layout_gravity 和 gravity的区别

發布時間:2024/3/12 Android 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Android layout_gravity 和 gravity的区别 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

????????這兩個屬性,有時候蠻容易混淆,好記性不如爛筆頭 ,還是直接記錄下來吧

1. android:layout_gravity定義:

android:layout_gravityGravity specifies how a component should be placed in its group of cells.

?android:layout_gravity 是指UI自身控件, 放在父布局中的哪個位置, 舉個例子:

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="300dp" tools:context=".MainActivity"><Buttonandroid:layout_width="70dp"android:background="#992288"android:layout_height="50dp"android:layout_gravity="bottom" # 把按鈕UI控件,放到父布局LinearLayout的底部位置android:text="點擊按鈕"/></LinearLayout>

2. android:gravity定義:?

android:gravity

.Specifies how an object should position its content,

?on both the X and Y axes, within its own bounds.

android:gravity? 是指UI控件里面的元素,放在UI控件里面的哪個位置?舉個例子:一個TextView 控件上的“hello?world”字符串,設置android:gravity=“right”,那么“hello world”會顯示在TextView的右邊

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="300dp" tools:context=".MainActivity"><TextViewandroid:layout_width="180dp"android:background="#992288"android:layout_height="50dp"android:gravity="right" #設置hello world字符串 在 TextView UI控件的右邊android:text="hello world"/></LinearLayout>

效果圖如下:

?3. 常用屬性值:

Constant

? ? ? ? ? ? ? ? ? ? ? ? ? Description

bottom

將對象放在其容器的底部,而不改變其大小。

center

將對象放在其容器的垂直和水平軸中心,不改變其大小。

center_horizontal

將對象放在其容器的水平中心,不改變其大小。

center_vertical

將對象放在其容器的垂直中心,不改變其大小。

end

將對象其容器的末尾,而不改變其大小。

left

將對象放到其容器的左側,而不改變其大小。

right

將對象到其容器的側,而不改變其大小。

start

將對象到其容器的起始位置,而不改變其大小。

top

將對象放到其容器的頂部,而不改變其大小。

clip_horizontal

附加選項,用于按照容器的邊來剪切對象的頂部和/或底部的內容. 剪切基于其縱向對齊設置:頂部對齊時,剪切底部;底部對齊時剪切頂部;除此之外剪切頂部和底部.

垂直方向裁剪

clip_vertical

附加選項,用于按照容器的邊來剪切對象的左側和/或右側的內容. 剪切基于其橫向對齊設置:左側對齊時,剪切右側;右側對齊時剪切左側;除此之外剪切左側和右側.

水平方向裁剪

fill

如果需要,增加對象的水平和垂直大小,使其完全填滿其容器.

fill_horizontal

如果需要,增加對象的水平尺寸,使其完全填滿其容器。

fill_vertical

如果需要,增加對象的垂直尺寸,使其完全填滿其容器。


4. 使用注意事項

? ? ? ? 第一:android:layout_gravity 是LinearLayout 線性布局中的屬性,在RelativeLayout?相對布

局中設置不會生效。

<?xml version="1.0" encoding="utf-8"?> <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="300dp"tools:context=".MainActivity"><TextViewandroid:id="@+id/test_textview"android:layout_width="180dp"android:layout_height="50dp"android:layout_gravity="right" <!-- android:layout_gravity 是LinearLayout中的屬性,所以在RelativeLayout相對布局中設置不生效, 所以TextView 不會居右顯示-->android:background="#992288"android:text="hello world" /><Buttonandroid:layout_width="100dp"android:layout_height="50dp"android:layout_below="@id/test_textview"android:layout_marginTop="20dp"android:background="@color/colorPrimary"android:text="按鈕點擊"android:gravity="right" <!--但是 android:gravity 也是RelativeLayout相對布局中的屬性,所以這里設置是有效的-->android:textSize="12sp" /> </RelativeLayout> 效果圖如下:

? ? ? ? ?第二: 當采用LinearLayout線性布局作為父布局,

? ? 1. 如果設置?android:orientation="horizontal" :? 元素布局排列為水平方向

這時android:layout_gravity 只有垂直方向的設置屬性才會生效,而水平方向的設置屬性不生效

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="300dp"android:orientation="horizontal"tools:context=".MainActivity"><TextViewandroid:id="@+id/test_textview"android:layout_width="180dp"android:layout_height="50dp"android:layout_gravity="right"android:background="#992288"android:text="hello world" /><!--由于設置的android:orientation="horizontal",android:layout_gravity在設置水平方向的屬性值 比如 left start right end 不會生效-這里我設置為right,預想會顯示在右邊,但實際上顯示在左側,不生效--><Buttonandroid:layout_width="100dp"android:layout_height="50dp"android:layout_marginTop="80dp"android:background="@color/colorPrimary"android:text="按鈕點擊"android:layout_gravity="bottom"android:textSize="12sp" /><!--由于設置的android:orientation="horizontal",android:layout_gravity在設置垂直平方向的屬性值 比如 top bottom center_vertical 會生效--></LinearLayout >

?效果圖:

?2. 如果設置?android:orientation="virtical" : 元素布局排列為垂直方向

這時android:layout_gravity 只有水平方向的設置屬性才會生效,而垂直方向的設置屬性不生效

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="300dp"android:orientation="vertical" tools:context=".MainActivity"><TextViewandroid:id="@+id/test_textview"android:layout_width="180dp"android:layout_height="50dp"android:layout_gravity="bottom"android:background="#992288"android:text="hello world" /><!--由于設置的android:orientation="virtical",android:layout_gravity在設置垂直方向的屬性值 比如 top bottom center_vertical不會生效雖然我設置的是bottom,預想顯示在底部,實際上不生效--><Buttonandroid:layout_width="100dp"android:layout_height="50dp"android:layout_gravity="left"android:layout_marginTop="80dp"android:background="@color/colorPrimary"android:text="按鈕點擊"android:textSize="12sp" /><!--由于設置的android:orientation="virtical",android:layout_gravity在設置水平平方向的屬性值 比如 start left right end 會生效--></LinearLayout>

效果圖:

總結

以上是生活随笔為你收集整理的Android layout_gravity 和 gravity的区别的全部內容,希望文章能夠幫你解決所遇到的問題。

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

主站蜘蛛池模板: 国产免费久久久 | 人妻无码一区二区三区 | 亚洲成人www | 日韩欧美一区二区在线 | 91精品一区二区三区在线观看 | 制服丝袜国产精品 | japanese中文字幕 | 欧美三级理论片 | 国产一区二区自拍 | 91精品国产综合久久久蜜臀图片 | 爱爱免费视频网站 | 操她视频网站 | 久国久产久精永久网页 | 欧美日韩一二 | 一级肉体全黄裸片 | 欧美三级特黄 | 欧美一区三区二区在线观看 | 五月婷婷亚洲综合 | 亚洲黄色三级视频 | 在线成人播放 | 影音先锋人妻啪啪av资源网站 | 久久精品无码专区免费 | 嘿咻视频在线观看 | 午夜国产在线 | av作品在线观看 | 午夜精品99 | 一级绝黄 | 日日射日日干 | 免费在线看黄视频 | 免费99精品国产自在在线 | 国产在线一卡二卡 | 日本泡妞视频 | 日本精品入口免费视频 | 高潮疯狂过瘾粗话对白 | 成人乱人乱一区二区三区一级视频 | 丰满岳妇乱一区二区三区 | 久久久久99 | 波多野结衣在线免费观看视频 | 亚洲男人天堂2024 | 日本一区视频在线播放 | 男人天堂av电影 | 131美女爱做视频 | 五月婷婷天堂 | 欧美大尺度床戏做爰 | 国产在线第一页 | 蜜臀在线播放 | 精品一区二区三区久久 | 极品国产91在线网站 | av电影在线播放 | 国产视频一区二区视频 | 亚洲欧美婷婷 | 五月天婷婷综合 | 青青久久av | 69精品人妻一区二区三区 | 国产日韩免费 | 69欧美视频 | 日韩免费片| 日本精品黄| 操欧洲美女 | 久草视频免费看 | 日韩字幕在线观看 | 激情黄色小说视频 | 亚洲免费网站在线观看 | 国产成人精品aa毛片 | 丁香六月五月婷婷 | 性无码专区无码 | 欧美天堂在线 | 欧美干 | 欧美成人一二区 | 麻豆系列在线观看 | 精品96久久久久久中文字幕无 | 欧美一级片在线 | 欧美a级大片 | 国产av电影一区二区三区 | 涩漫天堂| 少妇15p | 99热综合 | 九九九视频在线观看 | 日韩在线三区 | 欧美黑人精品一区二区不卡 | 深夜福利网站 | 少妇又色又紧又爽又刺激视频 | 天天射天天干天天 | 中文乱码人妻一区二区三区视频 | 日本少妇激三级做爰在线 | 另类捆绑调教少妇 | jizzjizz视频 | 91亚洲精品久久久蜜桃网站 | 日韩乱码人妻无码系列中文字幕 | 日韩视频免费观看高清 | 欧美成人动态图 | 一区二区三区网站 | 小色瓷导航 | 午夜激情视频在线播放 | 国产丝袜视频 | av天天在线 | 一级片视频免费观看 | 91人妻一区二区 | 天天做天天爱夜夜爽 |