drawable 半圆
时间: 2024-02-10 11:04:14 浏览: 29
要绘制一个半圆形的drawable,你可以使用XML定义一个shape,然后使用旋转变换将其旋转90度,从而得到一个半圆形。
下面是一个示例代码:
```xml
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#FF0000" />
<corners android:radius="10dp" />
<size android:width="20dp" android:height="40dp" />
</shape>
```
你需要在代码中将这个drawable进行旋转,如下所示:
```java
// 获取drawable资源
Drawable drawable = getResources().getDrawable(R.drawable.half_circle);
// 进行旋转变换
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
Matrix matrix = new Matrix();
matrix.postRotate(90);
drawable = new BitmapDrawable(getResources(), Bitmap.createBitmap(((BitmapDrawable) drawable).getBitmap(), 0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), matrix, true));
```
这样就可以得到一个半圆形的drawable了。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)