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

您的位置:首頁技術(shù)文章
文章詳情頁

詳解Android 硬布局item的高級(jí)寫法

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

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

效果:

詳解Android 硬布局item的高級(jí)寫法

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

比較

上下效果一致 行數(shù) 層級(jí) 上部分 121 3 下部分 55 2 下部分繼續(xù)精簡(jiǎn) 28 2

可以看出,對(duì)比還是很明顯的,精簡(jiǎn)到最后只有最開始的四分之一。

上部分

先看常規(guī)item寫法,橫向的LinearLayout嵌套三個(gè)子View,分別是

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

然后每個(gè)橫向的LinearLayout之間添加一個(gè)高度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://m.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='刪除個(gè)人信息'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://m.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://m.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://m.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://m.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='關(guān)于'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://m.b3g6.com/bcjs/@mipmap/ic_arrow_right' /> </LinearLayout> </LinearLayout>

可以看到嵌套雖然不深,但是已經(jīng)拉的很長(zhǎng),不易閱讀修改。且 哪怕是一層的嵌套優(yōu)化,也是優(yōu)化,積少成多。

下部分

利用TextView的drawableStart和drawableEnd屬性,來做簡(jiǎn)化,可以直接去掉左右兩邊的ImageView。至于分割線,利用LinearLayout的divider和showDividers屬性,寫個(gè)shape,來做簡(jiǎn)化,去掉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='刪除個(gè)人信息' 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='關(guān)于' 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>

可以看到,層級(jí)減少了,行數(shù)也減少了,看起來清爽多了。

style簡(jiǎn)化

盡管如此,我們還是有可以簡(jiǎn)化的空間。TextView有一些共同屬性,可以抽取做一個(gè)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>

再看簡(jiǎn)化后的代碼

<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='刪除個(gè)人信息' app:drawableStartCompat='@mipmap/ic_agreement' /> <TextView android: android:text='注銷賬戶' app:drawableStartCompat='@mipmap/ic_agreement' /> <TextView android: android:text='關(guān)于' app:drawableStartCompat='@mipmap/ic_agreement' /> </LinearLayout>

更加精簡(jiǎn)了,只有簡(jiǎn)化前的一半,共同屬性封裝,只需要關(guān)注業(yè)務(wù)參數(shù)。

核心屬性

LinearLayout

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

題外話,LinearLayout的android:animateLayoutChanges='true',可以在其子view添加移除的時(shí)候添加簡(jiǎn)單的動(dòng)畫。

TextView

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

到此這篇關(guān)于詳解Android 硬布局item的高級(jí)寫法的文章就介紹到這了,更多相關(guān)Android 硬布局item內(nèi)容請(qǐng)搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!

標(biāo)簽: Android
相關(guān)文章:
日本不卡不码高清免费观看,久久国产精品久久w女人spa,黄色aa久久,三上悠亚国产精品一区二区三区
欧美日韩精品一本二本三本 | 欧美日韩国产观看视频| 少妇精品导航| 婷婷亚洲精品| 久久精品亚洲人成影院 | 国产精东传媒成人av电影| 国语对白精品一区二区| 伊人久久大香线蕉av不卡| 亚洲欧美在线综合| 亚洲成人va| 亚洲一级在线| 日韩手机在线| 欧美1区2区3| 日韩视频网站在线观看| 久久影院午夜精品| 欧美成人亚洲| 亚洲色图国产| 99热精品久久| 亚洲精品一级| 日韩欧美一区免费| 日韩精品免费观看视频| 国产成人精品一区二区免费看京 | 久久国产尿小便嘘嘘| 日韩高清欧美| 日本伊人午夜精品| 日韩精品一区二区三区免费观看| 99久久久久国产精品| 久久国产精品久久w女人spa| 日韩精品视频在线看| 综合在线一区| 91九色综合| 久久激情婷婷| 日韩国产在线观看| 99热精品久久| 久久尤物视频| 国产农村妇女精品一二区| 欧美极品一区二区三区| 婷婷亚洲五月色综合| 国产精品日本一区二区不卡视频| 成人av二区| 91亚洲人成网污www| 日本久久二区| 亚洲视频播放| 高清av不卡| 国产精品一级在线观看| 视频一区欧美精品| 日韩国产激情| 麻豆精品国产91久久久久久| 午夜精品福利影院| 伊人久久成人| 成人羞羞在线观看网站| 欧美国产亚洲精品| 亚洲精品视频一二三区| 欧美 日韩 国产一区二区在线视频| 国产精品一级| 中文字幕一区二区三区日韩精品| 91精品久久久久久久久久不卡| 久久亚洲黄色| 国产精品成人一区二区网站软件| 亚洲va久久久噜噜噜久久| 欧美大黑bbbbbbbbb在线| 久久uomeier| 麻豆国产精品777777在线| 亚洲精品激情| 久久亚洲电影| 婷婷综合在线| 亚洲深夜视频| 精品精品国产三级a∨在线| 国产欧美视频在线| 亚洲精品麻豆| 免费一级片91| 亚洲中字黄色| 日韩午夜精品| 欧美日韩免费观看一区=区三区| 亚洲精品.com| 久久精品中文| 婷婷精品视频| 欧美成人高清| 中文日韩在线| 视频一区二区中文字幕| 国产亚洲网站| 久久精品卡一| 99精品视频精品精品视频| 亚洲播播91| 日本不良网站在线观看| 伊人久久国产| 亚洲成人精品| 在线国产一区| 快she精品国产999| 美女视频网站久久| 国产伊人精品| 亚洲性色av| 国产不卡人人| 精品久久电影| 国产精品啊v在线| 国产日韩欧美一区二区三区在线观看| 怡红院精品视频在线观看极品| 国产v日韩v欧美v| 精品国产aⅴ| 国产精品www.| 久久不见久久见免费视频7 | 久久久精品五月天| 色一区二区三区四区| 久久精品国产成人一区二区三区| 国产三级精品三级在线观看国产| 日韩在线观看一区二区三区| 蜜芽一区二区三区| 性欧美长视频| 国产亚洲高清视频| 欧美日韩激情在线一区二区三区| 亚洲网站视频| 欧美69视频| 伊人久久成人| 亚洲欧美日韩国产综合精品二区| 先锋影音久久久| 免费成人性网站| 亚洲精品精选| 欧美亚洲自偷自偷| 红杏一区二区三区| 国产亚洲一区二区手机在线观看 | 欧美日韩水蜜桃| 国产亚洲精品自拍| 青青伊人久久| 美日韩一区二区三区| 欧美二三四区| 久久午夜精品| 麻豆一区二区99久久久久| 国产一级成人av| 国产欧美日韩一区二区三区在线| 久久国产三级| 久久精品国产99国产| 欧美大黑bbbbbbbbb在线| 天堂av在线| 亚洲一级淫片| 成人午夜网址| 在线一区免费观看| 日韩亚洲精品在线观看| 精品九九在线| 99久久激情| 日本欧美在线| 欧美gv在线| 美女黄网久久| 亚洲伊人影院| 国产欧美三级| 97精品国产| 日韩天堂在线| 亚洲专区在线| 国产欧美欧美| 色偷偷偷在线视频播放| 九九久久电影| 日韩精品视频中文字幕| 久久亚州av| jiujiure精品视频播放| 国产亚洲综合精品| 日韩黄色av| 日韩综合在线| 国产色综合网| 欧美成人aaa| 蜜桃成人av| 久久激情五月婷婷| 丝袜美腿一区| 三级亚洲高清视频| 精品一区二区三区亚洲| 欧美一区二区三区高清视频| 亚洲乱亚洲高清| 国产999精品在线观看| 亚洲激情婷婷| 国产极品一区| 99久久久久国产精品| 香蕉久久久久久| 国产一区二区三区不卡视频网站 | 亚洲精品麻豆| 日韩专区视频网站| 国产精品激情电影| 视频小说一区二区| 欧美日韩在线精品一区二区三区激情综合| 欧美精品1区| 欧美日韩免费观看一区=区三区| 国产日韩1区| 欧美1级日本1级| 国产剧情一区二区在线观看| 久久精品国产99久久| 欧美午夜三级| 亚洲成人精品| 国产精品亚洲产品| 中文日韩在线| 91一区二区| 欧美精品中文字幕亚洲专区| 久久国产直播| 国产精品magnet| 欧美女激情福利| 黄色aa久久| 国产欧美69| 日韩av电影一区| 亚洲精品系列| 玖玖精品视频| 亚洲一区国产一区| 女同性一区二区三区人了人一 | 国产中文一区| 日韩久久电影|