频道栏目
首页 > 资讯 > Android > 正文

Android layer-list(边框加粗效果)

13-04-12        来源:[db:作者]  
收藏   我要投稿

 


要实现以上效果:当checkbox被选中之后,checkbox的边框被加粗(颜色改变、字体改变可容易实现,不再赘述)。暂时的解决方案是使用layer-list。

layer-list:图层的累加,字面上是多个层,也就是你可以把多个layer放在一起,然后一其显现出来。

 


tab-widget中自定义的视图checkbox所处布局:


[html]
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="40dp" 
    android:orientation="vertical"> 
 
    <CheckBox 
        android:id="@+id/checkMsg" 
        style="@style/tab_checkbox" 
        android:layout_width="match_parent" 
        android:layout_height="40dp" /> 
 
</LinearLayout> 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="40dp"
    android:orientation="vertical">

    <CheckBox
        android:id="@+id/checkMsg"
        style="@style/tab_checkbox"
        android:layout_width="match_parent"
        android:layout_height="40dp" />

</LinearLayout>
checkbox style.xml 样式文件:


[html]
<style name="tab_checkbox"> 
        <item name="android:background">@drawable/msg_tab_widget_sharp</item> 
        <item name="android:button" >@null</item> 
        <item name="android:textColor">@color/gray</item> 
        <item name="android:textSize" >16sp</item> 
        <item name="android:gravity" >center</item> 
    </style> 

<style name="tab_checkbox">
        <item name="android:background">@drawable/msg_tab_widget_sharp</item>
        <item name="android:button" >@null</item>
        <item name="android:textColor">@color/gray</item>
        <item name="android:textSize" >16sp</item>
        <item name="android:gravity" >center</item>
    </style>
msg_tab_widget_sharp.xml checkbox style.xml 样式文件中的background 的布局文件:

 

[html]
<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item android:drawable="@drawable/msg_tab_widget1" android:state_checked="true"></item> 
    <item android:drawable="@drawable/msg_tab_widget2" android:state_checked="false"></item> 
    <item android:drawable="@drawable/msg_tab_widget2"></item> 
</selector> 

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/msg_tab_widget1" android:state_checked="true"></item>
    <item android:drawable="@drawable/msg_tab_widget2" android:state_checked="false"></item>
    <item android:drawable="@drawable/msg_tab_widget2"></item>
</selector>
msg_tab_widget1.xml  当checkbox被选中时:


[html]
<?xml version="1.0" encoding="utf-8"?> 
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" > 
 
    <item> 
       <!-- This is the border color --> 
        <shape> 
            <solid android:color="#0066CC" /> 
        </shape> 
    </item> 
    <item android:bottom="3dp" android:right="1dp"> 
       <!-- This is the main color --> 
        <shape> 
            <solid android:color="#E9F2FC" /> 
 
            <padding 
                android:bottom="5dp" 
                android:left="5dp" 
                android:right="5dp" 
                android:top="5dp" /> 
        </shape> 
    </item> 
 
</layer-list> 

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

    <item>
       <!-- This is the border color -->
        <shape>
            <solid android:color="#0066CC" />
        </shape>
    </item>
    <item android:bottom="3dp" android:right="1dp">
       <!-- This is the main color -->
        <shape>
            <solid android:color="#E9F2FC" />

            <padding
                android:bottom="5dp"
                android:left="5dp"
                android:right="5dp"
                android:top="5dp" />
        </shape>
    </item>

</layer-list>
msg_tab_widget2.xml  当checkbox未被选中时,即默认显示的状态:

 

[html]
<?xml version="1.0" encoding="utf-8"?> 
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" > 
 
    <item> 
        <!-- This is the border color --> 
        <shape> 
            <solid android:color="#0066CC" /> 
        </shape> 
    </item> 
    <item 
        android:bottom="1dp" 
        android:right="1dp"> 
 
        <!-- This is the main color --> 
        <shape> 
            <solid android:color="#E9F2FC" /> 
 
            <padding 
                android:bottom="5dp" 
                android:left="5dp" 
                android:right="5dp" 
                android:top="5dp" /> 
        </shape> 
    </item> 
 
</layer-list> 

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

    <item>
        <!-- This is the border color -->
        <shape>
            <solid android:color="#0066CC" />
        </shape>
    </item>
    <item
        android:bottom="1dp"
        android:right="1dp">

        <!-- This is the main color -->
        <shape>
            <solid android:color="#E9F2FC" />

            <padding
                android:bottom="5dp"
                android:left="5dp"
                android:right="5dp"
                android:top="5dp" />
        </shape>
    </item>

</layer-list>

 

 

 

 


其他使用demo:如在 android:style/Widget.ProgressBar.Large 或者其他的progressbar风格


[html]
<style 
    name="progressBarStyleSmall" 
    parent="android:style/Widget.ProgressBar.Large" > 
 
    <item name="android:indeterminateDrawable">@drawable/progress</item> 
</style> 
 
 
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" > 
 
    <!-- <item android:drawable="@android:drawable/progress_circular_background" /> --> 
    <!-- 
      <item>  
         <shape android:shape="ring" android:innerRadiusRatio="3.4" android:thicknessRatio="6.0"> 
             <gradient android:useLevel="true" android:type="sweep" android:startColor="#ff000000" android:endColor="#ffffffff" />  
         </shape> 
      </item> 
    --> 
    <item> 
        <rotate 
            android:drawable="@drawable/load2" 
            android:fromDegrees="0" 
            android:pivotX="50%" 
            android:pivotY="50%" 
            android:toDegrees="370" /> 
    </item> 
 
</layer-list> 

<style
    name="progressBarStyleSmall"
    parent="android:style/Widget.ProgressBar.Large" >

    <item name="android:indeterminateDrawable">@drawable/progress</item>
</style>


<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

    <!-- <item android:drawable="@android:drawable/progress_circular_background" /> -->
    <!--
      <item>
         <shape android:shape="ring" android:innerRadiusRatio="3.4" android:thicknessRatio="6.0">
             <gradient android:useLevel="true" android:type="sweep" android:startColor="#ff000000" android:endColor="#ffffffff" />
         </shape>
      </item>
    -->
    <item>
        <rotate
            android:drawable="@drawable/load2"
            android:fromDegrees="0"
            android:pivotX="50%"
            android:pivotY="50%"
            android:toDegrees="370" />
    </item>

</layer-list>

 

相关TAG标签
上一篇:黑马程序员_java线程进阶
下一篇:hdu 1250 字典树+内存释放
相关文章
图文推荐

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训 | 举报中心

版权所有: 红黑联盟--致力于做实用的IT技术学习网站