如何建立透明的半圆? [英] How to create transparent semicircle?

查看:178
本文介绍了如何建立透明的半圆?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要创建这个effect.TextView与透明的半圆为backgound。 我尝试添加绘制作为背景。

I want to create this effect.TextView with transparent semicircle as backgound . I tried add drawable as background.

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval" >
    <solid android:color="#00000000" />
</shape>

也是我想这<一href="http://stackoverflow.com/questions/15962745/draw-a-semicircle-in-the-background-of-a-view">stackoverflow类似的问题,但它不为我工作。 谁能帮我?

also i tried this stackoverflow similar question ,but it doesn't work for me. Can anyone help me?

推荐答案

您无法从XML创建一个半圆。但你可以达到你在找什么用适当的利润率和放了一圈;填充。

You cannot create a semicircle from xml. but you could achieve what you are looking for using a circle with appropriate margin & padding.

创建一个固定大小的圆圈是这样的:

Create a fixed sized circle like this:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval"
    android:useLevel="false" >
    <solid android:color="#006AC5" />
    <size
        android:height="50dp"
        android:width="50dp" />
</shape>

现在使用它作为您的TextView的背景是这样的:

Now use it as the background of your TextView like this:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#FFFF00">

    <ImageView
        android:contentDescription="@string/app_name"
        android:id="@+id/img"
        android:layout_width="fill_parent"
        android:layout_height="200dip"
        android:layout_alignParentTop="true"
        android:background="#006AC5" />

    <TextView 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/img"
        android:layout_marginTop="-35dip"
        android:paddingTop="10dip"
        android:background="@drawable/circle"
        android:layout_centerHorizontal="true"
        android:text="@string/one"
        android:gravity="center"/>

</RelativeLayout>

现在,如果你给-25dip的顶边(圆的高度的一半)你的TextView,你会得到在底部一个完美的半圆,但我已经添加了又一个10dip(安培; 10dip填充,以保持代替文字)只是为了得到仔细看看你在找什么。

Now if you give a top margin of -25dip (half of circle's height) to your TextView, you'll get a perfect semicircle in the bottom, but I've added just another 10dip (& 10dip padding to keep the text in place) just to get a closer look to what you're looking for.

如果您还想要更改顶部的ImageView与放大器的背景;你不想圈内惹的外观的其他部分,你可以只添加的ImageView后添加的TextView所以它具有较高的z索引,和放大器;然后用一个单独的TextView来显示文本的图像上。这是很讨厌的,我知道,但它应该工作:)

If you further want to change background of the top ImageView & you don't want the rest of the circle to mess with the looks, you could just add the ImageView after you add the TextView so it would have a higher z-index, & then use a separate TextView to display text above the Image. It's quite nasty I know, but it should work :)

这篇关于如何建立透明的半圆?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆