圆润的内角与透明内部框架 [英] Rounded Inner corners with transparent inside frame
问题描述
我试图让从code一个框架,使我能够把它做圆角内眼角用实心填充外,透明的内部。 就像用透明的椭圆形内的实心矩形。的图片附后。我曾尝试一些形状组合,所有的在线显示可用的边角之外。
I am trying to make a frame from code so that I can apply it to make rounded inner corners with a solid fill outside and transparent inside. Just like a solid rectangle with transparent oval inside. picture attached. I have tried few shape combinations all that available online displays the corners outside.
里面应该是透明的不白。 该图像是从这个帖子但这里psented解决方案$ P $不算什么我在寻找我不想使用一个9补丁绘制,但想在code创建的。
The inside should be transparent not white. The image is taken from this post but the solution presented here is not what I am looking for I dont want to use a 9 patch drawable but would like to be created in code.
请唯一有效的答案。
推荐答案
首先创建绘制文件夹3 XML布局:
First of all create 3 xml layout in drawable folder :
第一:frame.xml
first : frame.xml
第二:frame_build.xml
second :frame_build.xml
thied:red.xml
thied : red.xml
(你可以随意更改此名称),
( you can change this name as you wish ),
frame.xml:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:bottom="20dp" android:drawable="@drawable/red" android:top="-25dp" />
<item android:bottom="15dp" android:drawable="@drawable/frame_build" android:top="5dp"
android:left="-5dp" android:right="-5dp" />
</layer-list>
frame_build.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<padding android:left="10dp" android:top="10dp" android:right="10dp"
android:bottom="10dp" />
<corners android:radius="40dp" />
</shape>
red.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke android:width="40dp" android:height="40dp" android:color="#B22222" />
<padding android:left="8dp" android:top="-1dp" android:right="8dp"
android:bottom="9dp" />
<corners android:radius="-10dp" />
</shape>
最后,请参阅您的视图或布局为框架XML如下:
Finally refer your view or layout to Frame XML as follow :
android:background="@drawable/frame"
此测试,如下图像输出:
This tested and output as below image :
希望这有助于。
这篇关于圆润的内角与透明内部框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!