Android Shape 的使用
生活随笔
收集整理的這篇文章主要介紹了
Android Shape 的使用
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
學而時習,溫故而知新。
今天復習shape 畫各種常見類型的背景圖
使用:
當在?java 代碼R.drawable.文件的名稱
當在布局中時 android:background=“@drawable/文件的名字”
?
位置在
res下面的drawable 里面
?
1 先看下shape可以指定幾種類型
line 線行
oval 橢圓?
rectangle 長方形
ring 環行
2 shape 里面常用的屬性
2.1 corners 圓角
角度可以單獨四個角 指定如下圖
2.2? solid 填充屬性 ,一般我們設置顏色,線的寬度 里面的屬性一般就是color?
2.3 stock 邊的屬性?
里面的屬性如下
2.4?size 大小設置 一般是設置畫的背景大小
2.5 gradient 漸變屬性,一般畫顏色不同的背景 屬性如下
2.6 padding 這個就是邊距屬性
顯示畫一些背景
1 帶有圓角的長方形
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"><corners android:radius="10dp" /><solid android:color="@color/colorAccent" /><sizeandroid:width="200dp"android:height="44dp" /></shape>
效果圖
2 畫一個帶邊線的長方形
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"><corners android:radius="10dp" /><stroke android:color="@color/colorAccent" android:width="1dp" ><sizeandroid:width="200dp"android:height="44dp" /></shape>
?
效果圖
?
3 上面2個圓角的長方形
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"><cornersandroid:topLeftRadius="20dp"android:topRightRadius="20dp" /><solid android:color="@color/colorAccent" /></shape>
效果圖
4 畫一個漸變色的背景圖
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"><gradientandroid:centerColor="#4A63FF"android:endColor="#6320DE"android:startColor="#558EFB" /><sizeandroid:width="200dp"android:height="100dp" />
</shape>
效果圖
?
5 畫一個圓
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"android:shape="oval"><solid android:color="@color/colorAccent" /><sizeandroid:width="200dp"android:height="200dp" />
</shape>
效果圖
6 畫一個圓環
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"android:shape="oval"><strokeandroid:width="10dp"android:color="@color/colorAccent" /><sizeandroid:width="200dp"android:height="200dp" />
</shape>
效果圖
?
7 畫一個有虛線組成的圓
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"android:shape="oval"><strokeandroid:width="10dp"android:color="@color/colorAccent"android:dashGap="5dp"android:dashWidth="5dp"/><sizeandroid:width="200dp"android:height="200dp" />
</shape>
效果圖
修改屬性?
8 變成虛線的長方形
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"android:shape="rectangle"><strokeandroid:width="10dp"android:color="@color/colorAccent"android:dashGap="5dp"android:dashWidth="50dp"/><sizeandroid:width="400dp"android:height="200dp" />
</shape>
效果圖
?
?9 改成橢圓
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"android:shape="oval"><strokeandroid:width="10dp"android:color="@color/colorAccent"android:dashGap="5dp"android:dashWidth="50dp"/><sizeandroid:width="400dp"android:height="200dp" />
</shape>
效果圖
10 畫一個半圓
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"android:shape="rectangle"><cornersandroid:topLeftRadius="180dp"android:topRightRadius="180dp" /><solid android:color="@color/colorAccent" /><sizeandroid:width="400dp"android:height="200dp" />
</shape>
?效果圖
?
總結
以上是生活随笔為你收集整理的Android Shape 的使用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 考托福多少钱啊?
- 下一篇: 求精灵旅社3百度云资源谢谢