欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android?LinearLayout快速設(shè)置每個item間隔

 更新時間:2023年07月23日 08:56:54   作者:Stars-one  
這篇文章主要介紹了Android?LinearLayout快速設(shè)置每個item間隔的相關(guān)資料,需要的朋友可以參考下

平常使用LinearLayout的時候,有時候會需要對每個item設(shè)置間距,但是每個item都加上margin的方法實在有些繁瑣

因為之前是在寫JavaFx程序,里面的Vbox或Hbox都會提供一個Space的參數(shù),可以用來快速設(shè)置每個item之間的間距

而Android這邊,是沒看見對應(yīng)的方法,于是搜索了一番,發(fā)現(xiàn)了可以通過divider分割線來一鍵設(shè)置item間距

實現(xiàn)步驟

1.創(chuàng)建divider對象

在drawble文件夾里面創(chuàng)建一個名為shape_option_item_pading.xml對象,然后設(shè)置寬高大小,這里我是針對垂直排列的線性布局,讓每個item間隔16dp,所以只設(shè)置了高度

xml代碼如下所示:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <size
        android:width="0dp"
        android:height="16dp" />
</shape>

當(dāng)然,這里你也可以加上背景色

2.LinearLayout使用

<androidx.appcompat.widget.LinearLayoutCompat
	app:divider="@drawable/shape_option_item_pading"
	app:showDividers="middle"
	android:layout_width="match_parent"
	android:layout_height="wrap_content"
	android:orientation="vertical">
</androidx.appcompat.widget.LinearLayoutCompat>
  • divider 設(shè)置為創(chuàng)建好的shape_option_item_pading.xml對象

  • showDividers 設(shè)置顯示類型,有4種類型可選:beginning end middle none

  • beginning 開頭設(shè)置分割線

  • end 末尾設(shè)置分割線

  • middle 中間設(shè)置分割線

  • none 不設(shè)置分割線

也很好理解,我們需要中間每個item自動加上間距,所以上述代碼就是選用了middle

到此這篇關(guān)于Android LinearLayout快速設(shè)置每個item間隔的文章就介紹到這了,更多相關(guān)Android LinearLayout設(shè)置item間隔內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論