一、设置边框圆角:

1.在drawable下新建文件:

image.png

2.写入要设置的圆角的尺寸和背景颜色,边距等等,写在布局文件里面,然后调用即可:

image.png

3.在布局里面调用:

image.png

4.结果为:

image.png

5.代码:

  1. <shape xmlns:android="http://schemas.android.com/apk/res/android">
  2. <!-- 背景颜色 -->
  3. <solid android:color="#f35319" />
  4. <!-- android:radius 弧形的半径 -->
  5. <corners android:radius="12px"/>
  6. <!-- padding:Button里面的文字与Button边界的间隔 -->
  7. </shape>

二、给背景设置渐变色:

1.在drawable下新建文件:

image.png

2.写入要设置的背景的开始颜色和结束颜色等等,然后再布局文件里面写入即可:

  1. <shape xmlns:android="http://schemas.android.com/apk/res/android"
  2. android:shape="rectangle">
  3. <gradient
  4. android:startColor="#ffffff"
  5. android:endColor="#00ffffff"
  6. android:angle="90"
  7. />
  8. </shape>

3.在布局里面写入:

image.png

4.结果为:

image.png

5.代码:

  1. 1test_white_bg.xml布局文件代码:
  1. <shape xmlns:android="http://schemas.android.com/apk/res/android"
  2. android:shape="rectangle">
  3. <gradient
  4. android:startColor="#ffffff"
  5. android:endColor="#00ffffff"
  6. android:angle="90"
  7. />
  8. </shape>
  1. 2activity_main.xml布局文件代码:
  1. <ImageView
  2. android:layout_width="match_parent"
  3. android:layout_height="200dp"
  4. android:layout_gravity="bottom"
  5. android:src="@drawable/test_white_bg"
  6. />