android个人笔记:圆角,线,框,渐变

新建xml文件(corners_layout),比如放于drawable-mdpi (其它位置也是可以的,自己选择)

基本格式 :
<?xml version="1.0" encoding="utf-8"?>  
<shape xmlns:android="http://schemas.android.com/apk/res/android">  

</shape>  


corners表示圆角属性,bottomRightRadius(左下角向右缩进半径)
   表示圆角半径为5dp
<cornersandroid:radius="5dp"/>

<code class="xml plain"><span style="line-height:18px; font-family:tahoma,arial,sans-serif; color:#444444"><span style="padding-bottom:0px; line-height:18px; margin:0px; padding-left:0px; padding-right:0px; font-family:tahoma,arial,sans-serif; color:#444444; padding-top:0px">//solid表示填充颜色</span></span></code>
<solid android:color="#ffffff" />

在shape里可先定义类型:
线:
android:shape="line"
线的格式设置:
其中,线的宽度为dashWith,线之间的空隙的宽度为dashGap,当dashGap=0dp时,为实线
    <stroke
        android:dashGap="3dp"
        android:dashWidth="6dp"
<span><span class="attribute">	android:layerType</span><span>=</span><span class="attribute-value">"software"</span><span> </span></span>
        android:width="1dp"
        android:color="#787878" />
	<!-- 线的高度 -->
    <size android:height="1dp" />

框:
框的边的粗细度 及 颜色 (同线的设定)
android:shape="rectangle"
<stroke android:width="2dp" android:color="#234323"></stroke>

框的填充效果激变:

 <gradient android:startColor="#ffffff"   
         android:endColor="#000000"  
         android:angle="270"/>  



引用方式为:
android:background="@drawable/corners_layout"

搬运货:点击渐变效果
<style name="list_item_top">
	<item name="android:clickable">true</item>
	<item name="android:focusable">true</item>
	<item name="android:paddingTop">10dip</item>
	<item name="android:paddingBottom">10dip</item>
	<item name="android:paddingLeft">10dip</item>
    	<item name="android:paddingRight">10dip</item>
    	<item name="android:gravity">center_vertical</item>
    	<item name="android:background">@drawable/background_view_rounded_top</item>
</style>

<?xml version="1.0" encoding="UTF-8"?>
<inset xmlns:android="http://schemas.android.com/apk/res/android"
    android:insetLeft="1.0px"
    android:insetRight="1.0px" >

    <selector>
        <item android:state_pressed="true">
            <shape>
                <gradient
                    android:angle="270.0"
                    android:endColor="@color/base_end_color_pressed"
                    android:startColor="@color/base_start_color_pressed" />

                <corners
                    android:bottomLeftRadius="0.0dip"
                    android:bottomRightRadius="0.0dip"
                    android:radius="2.0dip"
                    android:topLeftRadius="10.0dip"
                    android:topRightRadius="10.0dip" />
                
                <stroke 
                    android:width="1dp" 
                    android:color="#eededede" />
            </shape>
        </item>
        <item>
            <shape>
                <gradient
                    android:angle="270.0"
                    android:endColor="@color/base_end_color_default"
                    android:startColor="@color/base_start_color_default" />

                <corners
                    android:bottomLeftRadius="0.0dip"
                    android:bottomRightRadius="0.0dip"
                    android:radius="2.0dip"
                    android:topLeftRadius="11.0dip"
                    android:topRightRadius="11.0dip" />
                
                <stroke 
                    android:width="1dp" 
                    android:color="#eededede" />
            </shape>
        </item>
    </selector>

</inset>



  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值