如何将相对背景颜色设置为半圆?

时间:2015-08-14 04:56:59

标签: android layout

我创建相对布局我想在背面设置半圆形的背景颜色。我给了下面的显示。请帮助我。enter image description here

3 个答案:

答案 0 :(得分:2)

enter image description here

只需将其复制并粘贴到DRAWABLE文件夹中的half_circle.xml中即可。

<?xml version="1.0" encoding="utf-8"?>
 <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle">
 <corners
    android:bottomLeftRadius="190dp"
    android:bottomRightRadius="190dp"
    android:topLeftRadius="0dp"
    android:topRightRadius="0dp" />
 <padding
    android:bottom="0dp"
    android:left="0dp"
    android:right="0dp"
    android:top="0dp" />
 <stroke
    android:width="0dp" />
 <gradient
    android:startColor="#2196f3"
    android:endColor= "#2196f3"
    android:angle="90" />
 </shape>

像这样使用

  <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:weightSum="100">
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="48"
        android:background="@drawable/half_filled_circle">
     </RelativeLayout>
 </LinearLayout>

答案 1 :(得分:1)

您可以创建9-patch图像并将其设置为背景。贴片(可伸缩的部分)将设置在半圆末端的正下方。

答案 2 :(得分:1)

您可以使用Path指定paint.setStyle(FILL)然后在您的视图onDraw(Canvas c)中使用canvas.drawPath(path,paint)绘制路径。

您可以按以下顺序定义包含两个LayerList DrawableShape Drawable

  1. 创建一个矩形
  2. 创建一个椭圆
  3. 您现在已完成将此图层列表可绘制为任何视图或布局作为背景。

    您可以拥有九张补丁图片。

相关问题