展会信息港展会大全

android LISTVIew 加分割线
来源:互联网   发布日期:2015-11-26 11:13:44   浏览:3480次  

导读:分割线样式文件:?xml version=1.0 encoding=utf-8? layer-list xmlns:android=http://schemas.android.com/apk/res/android item shape ......

分割线样式文件:

<?xml version="1.0" encoding="utf-8"?>

<layer-list

xmlns:android="http://schemas.android.com/apk/res/android">

<item>

<shape>

<gradient

android:startColor="#000000"

android:centerColor="#CCCCCC"

android:endColor="#FFFFFF"

android:height="1px"

android:angle="0" />

</shape>

</item>

</layer-list>

LISTVIEW 样式

<ListView

android:layout_weight="1"

android:id="@+id/contactsList"

android:layout_height="wrap_content"

android:layout_width="fill_parent"

android:fastScrollEnabled="true"

android:layout_below="@+id/myAdapter_btn"

android:background="#000000"

android:headerDividersEnabled="false"

android:footerDividersEnabled="false"

android:divider="@drawable/sslist_driver"

android:dividerHeight="1dip"

>

</ListView>

标签内容显而易见,下附常用布局标签:

Android控件样式自定义是用定义在drawable文件夹下的XML文件实现,在布局文件中通过设置控件的background属性达到效果。

一、控件常见状态:在XML文件中用到了selector节点,selector可以理解为状态切换器,不同的状态下切换不同的样式,各种状态用Item节点表示,以下为一些常见的状态(注意:statelist中第一个匹配当前状态的item会被使用。因此,如果第一个item没有任何状态特性的话,那么它将每次都被使用,这也是为什么默认的值必须总是在最后,各种状态可以交叉使用):

1、android:state_pressed boolean。 true 表示按下状态使用(例如按钮按下); false 表示非按下状态使用。

2、android:state_focused boolean。 true 表示聚焦状态使用(例如使用滚动球/d-pad聚焦button); false 表示非聚焦状态使用.

3、android:state_selected boolean。 true 表示选中状态使用(例如tab打开); false 表示非选中状态使用。

4、android:state_checkable boolean。 true 表示可勾选状态时使用; false 表示非可勾选状态使用。(只对能切换可勾选 非可勾选的构件有用。)

5、android:state_checked boolean。 true 表示勾选状态使用; false 表示非勾选状态使用。

6、android:state_enabled boolean。 true 表示可用状态使用(能接收触摸/点击事件); false 表示不可用状态使用。

7、android:window_focused boolean。 true 表示应用程序窗口有焦点时使用(应用程序在前台); false 表示无焦点时使用(例如notification栏拉下或对话框显示)。

二、shape的属性:每个状态(item)都对应着一个效果,shape是用来定义形状的,以下为shape的一些常见属性:

1、solid:实心,就是填充的意思android:color指定填充的颜色

2、gradient:渐变android:startColor和android:endColor分别为起始和结束颜色,android:angle是渐变角度,必须为45的整数倍当angle=0时,渐变色是从左向右。 然后逆时针方向转,当angle=90时为从下往上。另外渐变默认的模式为android:type="linear",即线性渐变,可以指定渐变为径向渐变,android:type="radial",径向渐变需要指定半径android:gradientRadius="50",也可一指定二者的综合,扫描渐变 android: type="sweep"

3、stroke:描边android:width="2dp" 描边的宽度,android:color 描边的颜色。我们还可以把描边弄成虚线的形式,设置方式为:android:dashWidth="5dp"android:dashGap="3dp" 其中android:dashWidth表示'-'这样一个横线的宽度,android:dashGap表示之间隔开的距离。

4、corners:圆角android:radius为角的弧度,值越大角越圆。我们还可以把四个角设定成不同的角度,方法为: android:topRightRadius="20dp" 右上角

android:bottomLeftRadius="20dp" 右下角

android:topLeftRadius="1dp" 左上角

android:bottomRightRadius="0dp" 左下角

这里有个地方需要注意,bottomLefRadius是右下角,而不是左下角

5、panding:内边矩

首先是stackFromBottom属性,这只该属性之后你做好的列表就会显示你列表的最下面,值为true和false

android:stackFromBottom="true"

第二是 transciptMode属性,需要用ListView或者其它显示大量Items的控件实时跟踪或者查看信息,并且希望最新的条目可以自动滚动到可视范围内。通过设置的控件transcriptMode属性可以将Android平台的控件(支持ScrollBar)自动滑动到最底部。

android:transcriptMode="alwaysScroll"

第三cacheColorHint属性,很多人希望能够改变一下它的背景,使他能够符合整体的UI设计,改变背景背很简单只需要准备一张图片然后指定属性 android:background="@drawable/bg",不过不要高兴地太早,当你这么做以后,发现背景是变了,但是当你拖动,或者点击list空白位置的时候发现ListItem都变成黑色的了,破坏了整体效果。

如果你只是换背景的颜色的话,可以直接指定android:cacheColorHint为你所要的颜色,如果你是用图片做背景的话,那也只要将android:cacheColorHint指定为透明(#00000000)就可以了

第四divider属性,该属性作用是每一项之间需要设置一个图片做为间隔,或是去掉item之间的分割线

android:divider="@drawable/list_driver"其中@drawable/list_driver 是一个图片资源,如果不想显示分割线则只要设置为android:divider="@drawable/@null" 就可以了

第五fadingEdge属性,上边和下边有黑色的阴影

android:fadingEdge="none" 设置后没有阴影了~

第五scrollbars属性,作用是隐藏listView的滚动条,

android:scrollbars="none"与setVerticalScrollBarEnabled(true);的效果是一样的,不活动的时候隐藏,活动的时候也隐藏

第六fadeScrollbars属性,android:fadeScrollbars="true"配置ListView布局的时候,设置这个属性为true就可以实现滚动条的自动隐藏和显示

(此处为转,不知何处)

<?xml version="1.0" encoding="utf-8"?>

<selector

xmlns:android="http://schemas.android.com/apk/res/android">

<item android:state_pressed="true" >

<shape>

<gradient

android:startColor="#ff8c00"

android:endColor="#FFFFFF"

android:angle="270" />

<stroke

android:width="2dp"

android:color="#dcdcdc" />

<corners

android:radius="2dp" />

<padding

android:left="10dp"

android:top="10dp"

android:right="10dp"

android:bottom="10dp" />

</shape>

</item>

<item android:state_focused="true" >

<shape>

<gradient

android:startColor="#ffc2b7"

android:endColor="#ffc2b7"

android:angle="270" />

<stroke

android:width="2dp"

android:color="#dcdcdc" />

<corners

android:radius="2dp" />

<padding

android:left="10dp"

android:top="10dp"

android:right="10dp"

android:bottom="10dp" />

</shape>

</item>

<item>

<shape>

<gradient

android:startColor="#ff9d77"

android:endColor="#ff9d77"

android:angle="270" />

<stroke

android:width="2dp"

android:color="#fad3cf" />

<corners

android:radius="2dp" />

<padding

android:left="10dp"

android:top="10dp"

android:right="10dp"

android:bottom="10dp" />

</shape>

</item>

</selector>

赞助本站

人工智能实验室

相关热词: 分割线

AiLab云推荐
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港