1.android中可以通過(guò)xml文件配置資源,比如字符串啦,整數(shù)拉。浮點(diǎn)數(shù)等等,當(dāng)然也可以配置圖片資源和選擇器,下面我們就看看幾種圖片資源的配置。
@1矩形方框,帶漸變色的配置代碼
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android"> <!--設(shè)置黑色邊框--> <stroke android:color="#000" android:width="2px"/> <!--設(shè)置漸變--> <gradient android:angle="360" android:endColor="#c0c0c0" android:startColor="#fcd209"/> <!--設(shè)置邊距--> <padding android:left="5dp" android:top="5dp" android:right="5dp" android:bottom="5dp"/></shape>
看看效果:
@2帶圓角的矩形框
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <!--設(shè)置透明背景色--> <!----> <solid android:color="#87ceeb"/> <stroke android:width="2px" android:color="#000"/> <!--設(shè)置四個(gè)圓角半徑--> <corners android:topRightRadius="10px" android:bottomRightRadius="10px" android:topLeftRadius="10px" android:bottomLeftRadius="10px" /> <padding android:left="5dp" android:right="5dp" android:top="5dp" android:bottom="5dp"/></shape>
看看效果:
@3橢圓形drawable代碼
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval"> <solid android:color="#88005621"/> <stroke android:color="#000000" android:width="2px"/> <corners android:radius="20dp"/></shape>
看看效果:
@4環(huán)形資源代碼
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_main" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.market.shapedrawable.MainActivity"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:padding="100dp" android:background="@drawable/ring" android:text="Hello World!" /></RelativeLayout>
看看效果:
@5原點(diǎn)或?qū)嵭膱A資源代碼
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval"> <solid android:color="#ff2236"/> <size android:width="10dp" android:height="10dp" /></shape>
看看效果:
標(biāo)簽: android
http://www.cnblogs.com/huipengbo/p/7074890.html