xml布局内容总结(三)--Android

前端之家收集整理的这篇文章主要介绍了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>


正常状态: 点击:

原文链接:https://www.f2er.com/xml/296380.html

猜你在找的XML相关文章