一、设置边框圆角:
1.在drawable下新建文件:
2.写入要设置的圆角的尺寸和背景颜色,边距等等,写在布局文件里面,然后调用即可:
3.在布局里面调用:
4.结果为:
5.代码:
<shape xmlns:android="http://schemas.android.com/apk/res/android"> <!-- 背景颜色 --> <solid android:color="#f35319" /> <!-- android:radius 弧形的半径 --> <corners android:radius="12px"/> <!-- padding:Button里面的文字与Button边界的间隔 --></shape>
二、给背景设置渐变色:
1.在drawable下新建文件:
2.写入要设置的背景的开始颜色和结束颜色等等,然后再布局文件里面写入即可:
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <gradient android:startColor="#ffffff" android:endColor="#00ffffff" android:angle="90" /></shape>
3.在布局里面写入:
4.结果为:
5.代码:
(1)test_white_bg.xml布局文件代码:
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <gradient android:startColor="#ffffff" android:endColor="#00ffffff" android:angle="90" /></shape>
(2)activity_main.xml布局文件代码:
<ImageView android:layout_width="match_parent" android:layout_height="200dp" android:layout_gravity="bottom" android:src="@drawable/test_white_bg" />