日本不卡不码高清免费观看,久久国产精品久久w女人spa,黄色aa久久,三上悠亚国产精品一区二区三区

您的位置:首頁技術文章
文章詳情頁

詳解Android 硬布局item的高級寫法

瀏覽:134日期:2022-09-21 11:03:02

本文主要介紹了Android 硬布局item的高級寫法,分享給大家,具體如下:

效果:

詳解Android 硬布局item的高級寫法

這種布局應該是非常常見了,且寫的比較多。今天簡單探討一下效果圖中上下兩種布局的寫法。

比較

上下效果一致 行數 層級 上部分 121 3 下部分 55 2 下部分繼續精簡 28 2

可以看出,對比還是很明顯的,精簡到最后只有最開始的四分之一。

上部分

先看常規item寫法,橫向的LinearLayout嵌套三個子View,分別是

左邊的ImageView, 中間的TextView, 和右邊的ImageView。

然后每個橫向的LinearLayout之間添加一個高度1dp的View來作為橫線。

<LinearLayout android:layout_width='match_parent' android:layout_height='wrap_content' android:layout_marginStart='@dimen/dp_15' android:layout_marginTop='@dimen/dp_20' android:layout_marginEnd='@dimen/dp_15' android:layout_marginBottom='@dimen/dp_20' android:background='@drawable/shape_bg_white' android:orientation='vertical'> <LinearLayout android: android:layout_width='match_parent' android:layout_height='wrap_content' android:foreground='?android:attr/selectableItemBackground' android:gravity='center_vertical' android:orientation='horizontal' android:padding='@dimen/dp_20'> <ImageViewandroid:layout_width='wrap_content'android:layout_height='wrap_content'android:contentDescription='@string/app_name'android:src='http://www.b3g6.com/bcjs/@mipmap/ic_agreement' /> <TextViewandroid:layout_width='0dp'android:layout_height='wrap_content'android:layout_marginStart='@dimen/dp_20'android:layout_weight='1'android:includeFontPadding='false'android:text='刪除個人信息'android:textColor='@color/color_505258'android:textSize='@dimen/sp_14' /> <ImageViewandroid:layout_width='wrap_content'android:layout_height='wrap_content'android:contentDescription='@string/app_name'android:src='http://www.b3g6.com/bcjs/@mipmap/ic_arrow_right' /> </LinearLayout> <View android:layout_width='match_parent' android:layout_height='1dp' android:layout_marginStart='@dimen/dp_50' android:background='@color/color_F6F6F6' /> <LinearLayout android: android:layout_width='match_parent' android:layout_height='wrap_content' android:foreground='?android:attr/selectableItemBackground' android:gravity='center_vertical' android:orientation='horizontal' android:padding='@dimen/dp_20'> <ImageViewandroid:layout_width='wrap_content'android:layout_height='wrap_content'android:contentDescription='@string/app_name'android:src='http://www.b3g6.com/bcjs/@mipmap/ic_agreement' /> <TextViewandroid:layout_width='0dp'android:layout_height='wrap_content'android:layout_marginStart='@dimen/dp_20'android:layout_weight='1'android:includeFontPadding='false'android:text='注銷賬戶'android:textColor='@color/color_505258'android:textSize='@dimen/sp_14' /> <ImageViewandroid:layout_width='wrap_content'android:layout_height='wrap_content'android:contentDescription='@string/app_name'android:src='http://www.b3g6.com/bcjs/@mipmap/ic_arrow_right' /> </LinearLayout> <View android:layout_width='match_parent' android:layout_height='1dp' android:layout_marginStart='@dimen/dp_50' android:background='@color/color_F6F6F6' /> <LinearLayout android: android:layout_width='match_parent' android:layout_height='wrap_content' android:foreground='?android:attr/selectableItemBackground' android:gravity='center_vertical' android:orientation='horizontal' android:padding='@dimen/dp_20'> <ImageViewandroid:layout_width='wrap_content'android:layout_height='wrap_content'android:contentDescription='@string/app_name'android:src='http://www.b3g6.com/bcjs/@mipmap/ic_agreement' /> <TextViewandroid:layout_width='0dp'android:layout_height='wrap_content'android:layout_marginStart='@dimen/dp_20'android:layout_weight='1'android:includeFontPadding='false'android:text='關于'android:textColor='@color/color_505258'android:textSize='@dimen/sp_14' /> <ImageViewandroid:layout_width='wrap_content'android:layout_height='wrap_content'android:contentDescription='@string/app_name'android:src='http://www.b3g6.com/bcjs/@mipmap/ic_arrow_right' /> </LinearLayout> </LinearLayout>

可以看到嵌套雖然不深,但是已經拉的很長,不易閱讀修改。且 哪怕是一層的嵌套優化,也是優化,積少成多。

下部分

利用TextView的drawableStart和drawableEnd屬性,來做簡化,可以直接去掉左右兩邊的ImageView。至于分割線,利用LinearLayout的divider和showDividers屬性,寫個shape,來做簡化,去掉item之間做橫線的View。

<LinearLayout android:layout_width='match_parent' android:layout_height='wrap_content' android:layout_marginHorizontal='@dimen/dp_15' android:layout_marginVertical='@dimen/dp_20' android:background='@drawable/shape_bg_white' android:divider='@drawable/shape_divider_my' android:orientation='vertical' android:showDividers='middle'> <TextView android: android:layout_width='match_parent' android:layout_height='wrap_content' android:drawablePadding='@dimen/dp_16' android:foreground='?android:attr/selectableItemBackground' android:gravity='center_vertical' android:includeFontPadding='false' android:padding='@dimen/dp_20' android:text='刪除個人信息' android:textColor='@color/color_505258' android:textSize='@dimen/sp_14' app:drawableEndCompat='@mipmap/ic_arrow_right' app:drawableStartCompat='@mipmap/ic_agreement' /> <TextView android: android:layout_width='match_parent' android:layout_height='wrap_content' android:drawablePadding='@dimen/dp_16' android:foreground='?android:attr/selectableItemBackground' android:gravity='center_vertical' android:includeFontPadding='false' android:padding='@dimen/dp_20' android:text='注銷賬戶' android:textColor='@color/color_505258' android:textSize='@dimen/sp_14' app:drawableEndCompat='@mipmap/ic_arrow_right' app:drawableStartCompat='@mipmap/ic_agreement' /> <TextView android: android:layout_width='match_parent' android:layout_height='wrap_content' android:drawablePadding='@dimen/dp_16' android:foreground='?android:attr/selectableItemBackground' android:gravity='center_vertical' android:includeFontPadding='false' android:padding='@dimen/dp_20' android:text='關于' android:textColor='@color/color_505258' android:textSize='@dimen/sp_14' app:drawableEndCompat='@mipmap/ic_arrow_right' app:drawableStartCompat='@mipmap/ic_agreement' /> </LinearLayout>

shape:

<?xml version='1.0' encoding='utf-8'?><layer-list xmlns:android='http://schemas.android.com/apk/res/android'> <item android:left='@dimen/dp_50' > <shape android:shape='rectangle'> <solid android:color='@color/color_F6F6F6' /> <size android: /> </shape> </item></layer-list>

可以看到,層級減少了,行數也減少了,看起來清爽多了。

style簡化

盡管如此,我們還是有可以簡化的空間。TextView有一些共同屬性,可以抽取做一個style。

<style name='MyTextView'> <item name='android:layout_width'>match_parent</item> <item name='android:layout_height'>wrap_content</item> <item name='android:drawablePadding'>@dimen/dp_16</item> <item name='android:foreground'>?android:attr/selectableItemBackground</item> <item name='android:gravity'>center_vertical</item> <item name='android:includeFontPadding'>false</item> <item name='android:padding'>@dimen/dp_20</item> <item name='android:textColor'>@color/color_505258</item> <item name='android:textSize'>@dimen/sp_14</item> <item name='drawableEndCompat'>@mipmap/ic_arrow_right</item> </style>

再看簡化后的代碼

<LinearLayout android:layout_width='match_parent' android:layout_height='wrap_content' android:layout_marginHorizontal='@dimen/dp_15' android:layout_marginVertical='@dimen/dp_20' android:background='@drawable/shape_bg_white' android:divider='@drawable/shape_divider_my' android:orientation='vertical' android:showDividers='middle'> <TextView android: android:text='刪除個人信息' app:drawableStartCompat='@mipmap/ic_agreement' /> <TextView android: android:text='注銷賬戶' app:drawableStartCompat='@mipmap/ic_agreement' /> <TextView android: android:text='關于' app:drawableStartCompat='@mipmap/ic_agreement' /> </LinearLayout>

更加精簡了,只有簡化前的一半,共同屬性封裝,只需要關注業務參數。

核心屬性

LinearLayout

divider,分割線 showDividers,分割線的顯示方式 layout_marginVertical,代替原來的layout_marginTop、layout_marginBottom layout_marginHorizontal,代替原來的layout_marginStart、layout_marginEnd

題外話,LinearLayout的android:animateLayoutChanges='true',可以在其子view添加移除的時候添加簡單的動畫。

TextView

drawableEndCompat,即原來的drawableEnd,設置右邊的drawable,其他方向同理 drawablePadding,drawable與文字之前的內邊距 includeFontPadding,TextView默認top是有6dp的padding的,false可去掉,小細節 foreground,添加這個屬性會有水波紋的點擊效果,省了寫selector

到此這篇關于詳解Android 硬布局item的高級寫法的文章就介紹到這了,更多相關Android 硬布局item內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!

標簽: Android
相關文章:
日本不卡不码高清免费观看,久久国产精品久久w女人spa,黄色aa久久,三上悠亚国产精品一区二区三区
亚洲乱码久久| 99精品99| 在线亚洲精品| 国产99久久| 99国产精品一区二区| 日韩.com| 久久久久久色| 日韩欧美中文在线观看| 老牛国产精品一区的观看方式| 亚洲电影有码| av中文字幕在线观看第一页| 精品国产午夜肉伦伦影院| 日本精品另类| 中文亚洲免费| 亚洲一区二区三区免费在线观看| 婷婷精品进入| 亚洲影视一区二区三区| 日韩中文字幕不卡| 日韩在线a电影| 清纯唯美亚洲综合一区| 国产精品99精品一区二区三区∴ | 1000部精品久久久久久久久| 99久精品视频在线观看视频| 91精品蜜臀一区二区三区在线| 欧美特黄一级大片| 久久精品影视| 石原莉奈一区二区三区在线观看| 91成人在线网站| 日韩国产一区二区三区| 亚洲一区二区三区四区五区午夜 | 国产精品66| 日本а中文在线天堂| 午夜在线观看免费一区| 91精品麻豆| 1000部精品久久久久久久久| 一区二区精品| 久久爱www.| 在线亚洲激情| 99久久激情| 九色porny丨国产首页在线| 婷婷精品在线| 精品一区二区三区中文字幕| 亚洲成人三区| 国产精品一区高清| 国产一区一一区高清不卡| 国产亚洲一区二区手机在线观看| 在线国产一区| 99热国内精品| 91九色综合| 中文字幕一区二区三区日韩精品| 精品一区视频| 精品日韩毛片| 吉吉日韩欧美| 国产日韩免费| 国产女优一区| 99成人超碰| 久久天堂成人| 国产精品视频一区二区三区四蜜臂| 欧美日韩视频一区二区三区| 色老板在线视频一区二区| 久久精品国产亚洲夜色av网站 | 国产精品1luya在线播放| 99精品视频在线| 日韩精品一区二区三区中文在线| 136国产福利精品导航网址| 精品亚洲成人| 国产精品一区二区av交换| 日韩中文字幕区一区有砖一区 | 日韩不卡一区| 久久久精品国产**网站| 久久夜色精品| 久久久精品五月天| 欧美激情另类| 国产一区二区三区四区大秀| 国产精品伦一区二区| 久久午夜精品| 日本欧美在线看| 婷婷中文字幕一区| 激情欧美一区二区三区| 久久久精品午夜少妇| 韩国三级一区| 欧美精品资源| 亚洲人成在线网站| 精品国产欧美| 成人免费网站www网站高清| 欧美不卡在线| 欧美中文一区| 久久精品亚洲一区二区| 樱桃视频成人在线观看| 国产99久久| 一区二区三区四区日韩| 国产精品欧美日韩一区| 国产a亚洲精品| 国产精品亚洲综合色区韩国| 国产激情精品一区二区三区| 国产精品久久| 日韩精品免费一区二区三区| 亚洲精品1区| 欧美性www| 黄色免费成人| 亚洲乱码久久| 亚洲精品乱码| 99精品视频在线| 国产精品亚洲综合色区韩国| 精品一区不卡| 国产偷自视频区视频一区二区| 日本不卡一区二区| 国产亚洲精品精品国产亚洲综合| 日韩啪啪电影网| 午夜精品影视国产一区在线麻豆| 精品免费视频| 亚洲资源网站| 色婷婷狠狠五月综合天色拍| 牛牛精品成人免费视频| 精品高清久久| 在线亚洲观看| 精品久久久久中文字幕小说| 99久久夜色精品国产亚洲1000部| 午夜在线观看免费一区| 精品久久网站| 日韩国产欧美三级| 亚洲精品国产偷自在线观看| 亚洲精一区二区三区| 欧美日韩视频免费观看| 日韩在线成人| 国产真实久久| 国产精品精品| 国产精品嫩草影院在线看| 日韩精品一级中文字幕精品视频免费观看 | 日韩精品第二页| 免费在线观看一区| 亚洲一区二区三区久久久| 日韩欧美一区二区三区在线观看| 亚洲精品在线二区| 亚洲性色视频| 91一区二区| 婷婷精品在线观看| 国产韩日影视精品| 精品一区二区三区中文字幕在线| 99视频精品免费观看| 手机在线电影一区| 成人在线视频中文字幕| 国产精品黄色| 国产日韩欧美一区二区三区在线观看| aa亚洲婷婷| 怡红院精品视频在线观看极品| 成人国产精选| 国产探花在线精品一区二区| 91成人精品视频| 久久久久国产| 尤物在线精品| 免费人成黄页网站在线一区二区| 久久要要av| 亚洲激情中文| 国产高清一区二区| 国产欧美日韩一区二区三区四区 | 亚洲九九精品| 亚洲久久一区| 日韩国产在线不卡视频| 亚洲天堂成人| 一级欧美视频| 在线视频亚洲欧美中文| 国产婷婷精品| 丝袜美腿亚洲一区| 日韩精品一级二级| 亚洲欧美日韩专区| 日韩欧美中文字幕一区二区三区| 亚洲区国产区| 午夜亚洲福利| 日本亚洲三级在线| 日韩高清电影一区| 97精品久久| 黄毛片在线观看| 福利一区在线| 亚洲欧美日韩国产综合精品二区| 亚洲另类黄色| 精品视频久久| 久久高清免费| 石原莉奈一区二区三区在线观看| 日本中文字幕一区二区| 亚洲日本网址| 国产精品男女| 老司机精品久久| 免费看一区二区三区| 图片区亚洲欧美小说区| 精品久久在线| 蜜臀av亚洲一区中文字幕| 日韩视频网站在线观看| 亚洲精品在线a| 91精品国产91久久久久久黑人| 日韩高清在线一区| 一本一本久久| 精品日产乱码久久久久久仙踪林| 国产精品色网| 久久久成人网| 91青青国产在线观看精品| 国产欧美日韩亚洲一区二区三区| 亚洲激情中文在线| 国产精品久久久久久妇女| 亚洲三级视频|