1分割线样式文件: 2<?xml version="1.0" encoding="utf-8"?> 3<layer-list 4 xmlns:android="http://schemas.android.com/apk/res/android"> 5 <item> 6 <shape> 7 <gradient 8 android:startColor="#000000" 9 android:centerColor="#CCCCCC" 10 android:endColor="#FFFFFF" 11 android:height="1px" 12 android:angle="0" /> 13 </shape> 14 </item> 15</layer-list> 16LISTVIEW 样式 17<ListView 18 android:layout_weight="1" 19 android:id="@+id/contactsList" 20 android:layout_height="wrap_content" 21 android:layout_width="fill_parent" 22 android:fastScrollEnabled="true" 23 android:layout_below="@+id/myAdapter_btn" 24 android:background="#000000" 25 android:headerDividersEnabled="false" 26 android:footerDividersEnabled="false" 27 android:divider="@drawable/sslist_driver" 28 android:dividerHeight="1dip" 29 > 30</ListView> 31标签内容显而易见,下附常用布局标签: 32Android控件样式自定义是用定义在drawable文件夹下的XML文件实现,在布局文件中通过设置控件的background属性达到效果。 33一、控件常见状态:在XML文件中用到了selector节点,selector可以理解为状态切换器,不同的状态下切换不同的样式,各种状态用Item节点表示,以下为一些常见的状态(注意:statelist中第一个匹配当前状态的item会被使用。因此,如果第一个item没有任何状态特性的话,那么它将每次都被使用,这也是为什么默认的值必须总是在最后,各种状态可以交叉使用): 341、android:state_pressed boolean。“true”表示按下状态使用(例如按钮按下);“false”表示非按下状态使用。 352、android:state_focused boolean。“true”表示聚焦状态使用(例如使用滚动球/d-pad聚焦button);“false”表示非聚焦状态使用. 363、android:state_selected boolean。“true”表示选中状态使用(例如tab打开);“false”表示非选中状态使用。 374、android:state_checkable boolean。“true”表示可勾选状态时使用;“false”表示非可勾选状态使用。(只对能切换可勾选—非可勾选的构件有用。) 385、android:state_checked boolean。“true”表示勾选状态使用;“false”表示非勾选状态使用。 396、android:state_enabled boolean。“true”表示可用状态使用(能接收触摸/点击事件);“false”表示不可用状态使用。 407、android:window_focused boolean。“true”表示应用程序窗口有焦点时使用(应用程序在前台);“false”表示无焦点时使用(例如notification栏拉下或对话框显示)。 41二、shape的属性:每个状态(item)都对应着一个效果,shape是用来定义形状的,以下为shape的一些常见属性: 421、solid:实心,就是填充的意思 android:color指定填充的颜色 432、gradient:渐变 android:startColor和android:endColor分别为起始和结束颜色,android:angle是渐变角度,必须为45的整数倍当angle=0时,渐变色是从左向右。 然后逆时针方向转,当angle=90时为从下往上。另外渐变默认的模式为android:type="linear",即线性渐变,可以指定渐变为径向渐变,android:type="radial",径向渐变需要指定半径android:gradientRadius="50",也可一指定二者的综合,扫描渐变 android: type="sweep" 443、stroke:描边 android:width="2dp" 描边的宽度,android:color 描边的颜色。我们还可以把描边弄成虚线的形式,设置方式为:android:dashWidth="5dp" android:dashGap="3dp" 其中android:dashWidth表示'-'这样一个横线的宽度,android:dashGap表示之间隔开的距离。 454、corners:圆角 android:radius为角的弧度,值越大角越圆。我们还可以把四个角设定成不同的角度,方法为: android:topRightRadius="20dp" 右上角 46android:bottomLeftRadius="20dp" 右下角 47android:topLeftRadius="1dp" 左上角 48android:bottomRightRadius="0dp" 左下角 49这里有个地方需要注意,bottomLefRadius是右下角,而不是左下角 505、panding:内边矩 51 52首先是stackFromBottom属性,这只该属性之后你做好的列表就会显示你列表的最下面,值为true和false 53android:stackFromBottom="true" 54第二是 transciptMode属性,需要用ListView或者其它显示大量Items的控件实时跟踪或者查看信息,并且希望最新的条目可以自动滚动到可视范围内。通过设置的控件transcriptMode属性可以将Android平台的控件(支持ScrollBar)自动滑动到最底部。 55 android:transcriptMode="alwaysScroll" 56第三cacheColorHint属性,很多人希望能够改变一下它的背景,使他能够符合整体的UI设计,改变背景背很简单只需要准备一张图片然后指定属性 android:background="@drawable/bg",不过不要高兴地太早,当你这么做以后,发现背景是变了,但是当你拖动,或者点击list空白位置的时候发现ListItem都变成黑色的了,破坏了整体效果。 57如果你只是换背景的颜色的话,可以直接指定android:cacheColorHint为你所要的颜色,如果你是用图片做背景的话,那也只要将android:cacheColorHint指定为透明(#00000000)就可以了 58第四divider属性,该属性作用是每一项之间需要设置一个图片做为间隔,或是去掉item之间的分割线 59 android:divider="@drawable/list_driver" 其中 @drawable/list_driver 是一个图片资源,如果不想显示分割线则只要设置为android:divider="@drawable/@null" 就可以了 60第五fadingEdge属性,上边和下边有黑色的阴影 61android:fadingEdge="none" 设置后没有阴影了~ 62 第五scrollbars属性,作用是隐藏listView的滚动条, 63android:scrollbars="none"与setVerticalScrollBarEnabled(true);的效果是一样的,不活动的时候隐藏,活动的时候也隐藏 64第六fadeScrollbars属性,android:fadeScrollbars="true" 配置ListView布局的时候,设置这个属性为true就可以实现滚动条的自动隐藏和显示 65(此处为转,不知何处) 66 67 68 <?xml version="1.0" encoding="utf-8"?> 69<selector 70 xmlns:android="http://schemas.android.com/apk/res/android"> 71 <item android:state_pressed="true" > 72 <shape> 73 <gradient 74 android:startColor="#ff8c00" 75 android:endColor="#FFFFFF" 76 android:angle="270" /> 77 <stroke 78 android:width="2dp" 79 android:color="#dcdcdc" /> 80 <corners 81 android:radius="2dp" /> 82 <padding 83 android:left="10dp" 84 android:top="10dp" 85 android:right="10dp" 86 android:bottom="10dp" /> 87 </shape> 88 </item> 89 90 <item android:state_focused="true" > 91 <shape> 92 <gradient 93 android:startColor="#ffc2b7" 94 android:endColor="#ffc2b7" 95 android:angle="270" /> 96 <stroke 97 android:width="2dp" 98 android:color="#dcdcdc" /> 99 <corners 100 android:radius="2dp" /> 101 <padding 102 android:left="10dp" 103 android:top="10dp" 104 android:right="10dp" 105 android:bottom="10dp" /> 106 </shape> 107 </item> 108 109 <item> 110 <shape> 111 <gradient 112 android:startColor="#ff9d77" 113 android:endColor="#ff9d77" 114 android:angle="270" /> 115 <stroke 116 android:width="2dp" 117 android:color="#fad3cf" /> 118 <corners 119 android:radius="2dp" /> 120 <padding 121 android:left="10dp" 122 android:top="10dp" 123 android:right="10dp" 124 android:bottom="10dp" /> 125 </shape> 126 </item> 127</selector>
LISTVIew 加分割线
Stella981
2021-10-11
1351 0 0
点赞
收藏
评论区
加载中...