xml布局内容总结三--Android

关于xml中经常用到边框及边框效果,在此进行一下总结。

3.border(边框及边框效果

(1)直角边框线



<LinearLayout
android:layout_width="200dp"
android:layout_height="30dp"
android:layout_margin="10dp"
android:orientation="vertical"
android:background="@drawable/border_c"
>
</LinearLayout>

border_c.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- 填充颜色 -->
<solid android:color="@color/listitem_green" />
<!-- 边框宽度,颜色 -->
<stroke
android:width="0.1dp"
android:color="@color/black" />
<!-- 4个角度的弧度设置 -->
<corners
android:topLefTradius="0.0dip"
android:topRighTradius="0.0dip"
android:bottomLefTradius="0.0dip"
android:bottomrighTradius="0.0dip"
/>
</shape>

(2)圆角边框线



<LinearLayout
android:layout_width="200dp"
android:layout_height="30dp"
android:layout_margin="10dp"
android:orientation="vertical"
android:background="@drawable/border_s"
>
</LinearLayout>

border_s.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- 填充颜色 -->
<solid android:color="@color/yellow" />
<!-- 边框宽度,颜色 -->
<stroke
android:width="0.1dp"
android:color="@color/black" />
<!-- 4个角度的弧度设置 -->
<corners
android:topLefTradius="10.0dip"
android:topRighTradius="10.0dip"
android:bottomLefTradius="10.0dip"
android:bottomrighTradius="10.0dip"
/>
</shape>

(3)横线,竖线



<TextView
android:layout_width="200dp"
android:layout_height="0.5dp"
android:background="@color/black"
/>
<TextView
android:layout_marginTop="10dp"
android:layout_width="0.5dp"
android:layout_height="50dp"
android:background="@color/black"
/>

(4)按钮效果

<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:background="@drawable/btn_style_green"
android:text="Button"
android:textColor="@color/white"
/>

btn_style_green.xml

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

<item android:drawable="@drawable/button_green_bg" android:state_pressed="true"/>
<item android:drawable="@drawable/button_blue_bg" android:state_focused="false" android:state_pressed="false"/>

</selector>

button_green_bg.xml

<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/green" />
<stroke android:width="0.5dip" android:color="@color/black" />
<corners android:topLefTradius="5.0dip" android:topRighTradius="5.0dip" android:bottomLefTradius="5.0dip" android:bottomrighTradius="5.0dip" />
</shape>


button_blue_bg.xml

<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/blue" />
<stroke android:width="0.5dip" android:color="@color/black" />
<corners android:topLefTradius="5.0dip" android:topRighTradius="5.0dip" android:bottomLefTradius="5.0dip" android:bottomrighTradius="5.0dip" />
</shape>


正常状态: 点击:

相关文章

php输出xml格式字符串
J2ME Mobile 3D入门教程系列文章之一
XML轻松学习手册
XML入门的常见问题(一)
XML入门的常见问题(三)
XML轻松学习手册(2)XML概念