
不要说Android中UI做的丑是因为不会美化,其实做一个漂亮的界面也不是什么打不了的事情
简单一说:shape是用来自己画图用的 其中gradient可以让它有个一个渐变效果,startColor 是开始的颜色,endColor是最后的颜色,angle用来确定方向,0表示Left_Right 90是Bottom——Top 180是Right——Left发现规律了吧,剩下的自己应该知道了 stroke 是来确定边框的 其中width 是表示宽度,color是边框的颜色 corners 来确定每个角的半径,可以用 topLeftRadius 等来分别设置半径的大小,Padding 用开确定里面内容的位置,
当然我们也可以分开单独写<shape>然后用 android:drawable="@drawable/"来定义自己画的图片或者是已有的图片,这要看自己的用途
<?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="#FFFF00" android:endColor="#C0C0C0"
android:angle="0"/>
<stroke android:width="4dip" android:color="#b0000000"/>
<corners android:radius="15dp"/>
<padding android:left="10dp" android:top="10dp" android:right="10dp"
android:bottom="10dp"/>
</shape>
</item>
<item android:state_focused="true">
<shape>
<gradient android:startColor="#FFFFFFFF" android:endColor="#00000000"
android:angle="270"/>
<stroke android:width="4dip" android:color="#00000000"/>
<corners android:radius="15dp"/>
<padding android:left="10dp" android:top="10dp" android:right="10dp"
android:bottom="10dp"/>
</shape>
</item>
<item>
<shape>
<gradient android:startColor="#FFFFFFFF" android:endColor="#00000000"
android:angle="90"/>
<stroke android:width="4dip" android:color="#00000000"/>
<corners android:radius="15dp"/>
<padding android:left="10dp" android:top="10dp" android:right="10dp"
android:bottom="10dp"/>
</shape>
</item>
</selector>
本文详细介绍了在Android应用中如何使用shape、gradient、stroke、corners、padding等属性进行UI美化设计,通过设置开始和结束颜色、角度、宽度、边框颜色、角半径以及内容位置,实现界面的个性化定制。

213

被折叠的 条评论
为什么被折叠?



