gpt4 book ai didi

Android - 不透明度淡入淡出可绘制

转载 作者:行者123 更新时间:2023-11-29 14:28:29 25 4
gpt4 key购买 nike

是否可以仅使用可绘制对象来创建具有向外辐射的白色模糊的黑色背景?

这是最终产品,虽然齿轮是 ImageViwe,文本是 TextView,但我希望黑色 + 白色模糊成为单个可绘制对象,我可以将其分配给包含线性布局:

enter image description here

这是布局的代码(最终在 GridView 中使用)。如果可能,我想将 LinearLayout 的背景设置为上述 Drawable:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:background="#000000"
android:gravity="center_vertical|center_horizontal"
android:orientation="vertical"
android:padding="5dp" >

<ImageView
android:id="@+id/tile_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:adjustViewBounds="true"
android:contentDescription="@string/temp_image"
android:src="@drawable/ic_logo" />

<TextView
android:id="@+id/tile_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

</LinearLayout>

最佳答案

当然可以,下面是径向渐变drawable,将用作背景。更改颜色/渐变半径以获得所需的效果。 (在可绘制文件夹“radialbg”或您喜欢的名称中创建 xml 文件)

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#FFFFFFFF"
android:endColor="#00FFFFFF"
android:gradientRadius="270"
android:type="radial"/>

</shape>

要应用它,请在您的线性布局中使用以下行

android:background="@drawable/radialbg">

关于Android - 不透明度淡入淡出可绘制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10837267/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com