Android 如何制作曲线布局
我正在尝试使布局半透明我正在尝试的是使红色部分透明,而不是用强烈的颜色着色的部分。我可以将其设置为在一层的背面放置黑色层,但我想使其半透明,就像红色部分将显示放置在背面的图像一样。我如何做到这一点? 这是我尝试的xmlAndroid 如何制作曲线布局,android,xml,android-layout,layout,Android,Xml,Android Layout,Layout,我正在尝试使布局半透明我正在尝试的是使红色部分透明,而不是用强烈的颜色着色的部分。我可以将其设置为在一层的背面放置黑色层,但我想使其半透明,就像红色部分将显示放置在背面的图像一样。我如何做到这一点? 这是我尝试的xml <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <stroke android:width="0.5dp"
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke
android:width="0.5dp"
android:color="@color/white" />
<corners
android:bottomLeftRadius="150dp"
android:bottomRightRadius="1000dp"
android:topLeftRadius="0dp"
android:topRightRadius="0dp" />
<padding
android:bottom="0dp"
android:left="0dp"
android:right="0dp"
android:top="0dp" />
<solid android:color="@color/red"
/>
您可以将此形状放置在可绘制的图层列表中:
<?xml version="1.0" encoding="utf-8"?>
<layer-list
xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- black background -->
<item android:drawable="@android:color/black"/>
<!-- red shape on top of black background -->
<item android:drawable="@drawable/curved_shape"/>
</layer-list>
然后使用此图层列表作为背景。只需将布局放在黑色背景的图层列表中即可
<LinearLayout 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:orientation="horizontal"
android:background="#000000">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:background="@drawable/your_shape">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!" />
</LinearLayout>
</LinearLayout>
我想你已经掌握了曲线形状。要使其透明,请使用其颜色透明,而不是简单的<代码>红色代码>颜色。使用xml尝试以下代码
<gradient
android:angle="45"
android:endColor="#aaF00"
android:centerColor="#aaF00"
android:startColor="#aaF00" />
所以整个文件看起来像:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke
android:width="0.5dp"
android:color="@color/white" />
<corners
android:bottomLeftRadius="150dp"
android:bottomRightRadius="1000dp"
android:topLeftRadius="0dp"
android:topRightRadius="0dp" />
<padding
android:bottom="0dp"
android:left="0dp"
android:right="0dp"
android:top="0dp" />
<gradient
android:angle="45"
android:endColor="#aa000000"
android:centerColor="#aa000000"
android:startColor="#aa000000" />
/>
/>
我给你的红色加了阿尔法。提及
您也可以访问
希望这将帮助您:)在矩形上使用半径属性。简单!:)@14bce109你能举个例子吗;)在我的真实项目中,我用透明的部分替换红色部分,这样我就不能将背景设置为黑色,但我要使红色部分透明,这样如果我将黑色层放在后面,它将不透明。我如何使它半透明。这在XML中是不可行的。您需要编写一个自定义的
Drawable
,它将绘制一个路径
,并在路径内外放置不同的颜色。只需将@14bce109的概念和您的