【问题标题】:Is there any way how to create half circle as shape?有什么方法可以创建半圆形作为形状?
【发布时间】:2019-01-03 10:47:05
【问题描述】:

我想为我的应用创建特殊视图。它是垂直虚线和上下两个半圆。有什么方法可以将其创建为可绘制的单一形状吗?我画了虚线,但我不能画半圈。

它应该看起来像这样。

垂直虚线:

<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android" android:fromDegrees="90" android:toDegrees="90">
    <shape
            android:shape="line">
        <stroke
                android:color="#777777"
                android:dashWidth="7dp"
                android:dashGap="5dp"
                android:width="2dp"/>
    </shape>
</rotate>

我发现有人试图做半圈,但它很大。我只需要小圈子。它甚至不是圆。

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <corners
            android:bottomLeftRadius="100000dp"
            android:topLeftRadius="0dp"
            android:bottomRightRadius="100000dp"
            android:topRightRadius="0dp" />

    <solid android:color="#777777" />
</shape>

【问题讨论】:

标签: android android-drawable android-shape


【解决方案1】:

用这一行在drawable下创建half_circle.xml文件

<?xml version="1.0" encoding="utf-8"?>
<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid android:color="#8C9AEE"/>
    <size
    android:width="120dp"
    android:height="60dp"/>
   <corners
    android:topLeftRadius="60dp"
    android:topRightRadius="60dp"/>
</shape>

设置half_circle.xml为布局背景

输出将如下所示:

【讨论】:

    【解决方案2】:

    你可以在 android.Canvas 的帮助下绘制整个视图。并使用Path 来定义它的样子,并使用Paint 对象来定义它的颜色。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-10
      • 1970-01-01
      • 2019-07-28
      • 1970-01-01
      • 2021-11-17
      • 2021-08-18
      相关资源
      最近更新 更多