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

歡迎訪問 生活随笔!

生活随笔

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

Android

Android布局中涉及的一些属性

發布時間:2025/1/21 Android 44 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Android布局中涉及的一些属性 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Android:gravity屬性

??? 線性布局常見的就是利用LinearLayout進行布局,其中有個比較重要的屬性就是android:gravity,在官方文檔中是這么描述這個屬性的:指定一個元素怎么放置它的內容,包括在X和Y軸,在它自己的邊框中。

下面我們將在一個簡單的TextView中應用android:gravity屬性。假設我們想要TextView內的內容在右側顯示,那么我們就可以編寫對應的XML布局

<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="match_parent"android:background="#000000"android:orientation="vertical" ><TextViewandroid:layout_width="fill_parent"android:layout_height="wrap_content"android:layout_margin="@dimen/padding_medium"android:background="#ffffff"android:gravity="right"android:text="@string/hello_world"android:textColor="#ff0000"android:textSize="@dimen/font_size" /> </LinearLayout>

效果如下圖

盒模型

為了更加準確地控制TextView里面內容的位置,我們可以使用一系列的padding屬性來控制。在使用padding屬性之前,先科普一下padding和Marigin之間的區別,然后我們在通過實際的效果看看他們之間的差異。

下圖所示是一個類似盒子的模型,我們將通過下面的模型來講解Padding和Marigin之間的區別。從圖中可以看出,在Container(父控件)里面有一個子控件,假設是一個TextView控件。其中Margin是子控件與父控件之間的間隔大小。Border是子控件的邊框,它是子控件和父控件的邊界。Padding是指子控件中的內容(Content Area)與子控件Border的間隔大小。

margin屬性

Android中有一系列的margin屬性,下面讓我們看看其中的android:layout_marginRight屬性,為了有一個對比的效果,我們先將marginRight設為0dip,再將其設為50dip,如以下兩圖所示

android:layout_marginRight="0dip"

android:layout_marginRight="50dip"

從上圖中,我們可以看出,左圖TextView控件跟他的父控件的是沒有右間隔的,而右圖明顯的有一塊間隔(見右圖黃色圈圈部分)。

marginRight相同的還有以下屬性,它們的原理都相同,就不一一細講了。

屬性名相關方法描述
android:layout_marginBottomsetMargins(int,int,int,int)Specifies extra space on the bottom side of this view.
android:layout_marginEndsetMarginEnd(int)Specifies extra space on the end side of this view.
android:layout_marginLeftsetMargins(int,int,int,int)Specifies extra space on the left side of this view.
android:layout_marginRightsetMargins(int,int,int,int)Specifies extra space on the right side of this view.
android:layout_marginStartsetMarginStart(int)Specifies extra space on the start side of this view.
android:layout_marginTopsetMargins(int,int,int,int)Specifies extra space on the top side of this view.

?

padding屬性

下面讓我們來看看android:layout_paddingRight屬性。我們將在以下布局中,通過改變android:layout_paddingRight屬性,來看看變化。

為了有一個對比的效果,我們先將paddingRight設為0dip,再將其設為50dip,如以下兩圖所示

android:layout_paddingRight="0dip"android:layout_paddingRight="50dip"

從上圖中,我們可以看出,左圖TextView控件中的內容跟TextView的邊框(border)是沒有右間隔的,而右圖明顯的有一塊間隔(見右圖黃色圈圈部分)。

paddingRight相同的還有以下屬性,它們的原理都相同,就不一一細講了。

屬性名相關方法描述
android:paddingsetPaddingRelative(int,int,int,int)Sets the padding, in pixels, of all four edges.
android:paddingBottomsetPaddingRelative(int,int,int,int)Sets the padding, in pixels, of the bottom edge; see?padding.
android:paddingEndsetPaddingRelative(int,int,int,int)Sets the padding, in pixels, of the end edge; see?padding.
android:paddingLeftsetPadding(int,int,int,int)Sets the padding, in pixels, of the left edge; see?padding.
android:paddingRightsetPadding(int,int,int,int)Sets the padding, in pixels, of the right edge; see?padding.
android:paddingStartsetPaddingRelative(int,int,int,int)Sets the padding, in pixels, of the start edge; see?padding.
android:paddingTopsetPaddingRelative(int,int,int,int)Sets the padding, in pixels, of the top edge; see?padding.

?

示例代碼

轉載于:https://www.cnblogs.com/kissazi2/p/3309109.html

與50位技術專家面對面20年技術見證,附贈技術全景圖

總結

以上是生活随笔為你收集整理的Android布局中涉及的一些属性的全部內容,希望文章能夠幫你解決所遇到的問題。

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