gpt4 book ai didi

android - 具有纯色背景和顶部+底部内部阴影的 View

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:50:51 25 4
gpt4 key购买 nike

本质上,我正在尝试创建以下背景: enter image description here

我用在背景的drawable中使用的传统渐变只支持开始颜色、中间颜色和结束颜色。

但是,正如您从模型中看到的那样,我试图在形状的顶部和底部仅创建一个轻微的覆盖/阴影,颜色为 #50000000(黑色 50%不透明度)。

最佳答案

如果您在布局 View 中使用它,那么您可以简单地创建一个具有渐变背景的 View 并将其放置在布局的开头和结尾。

例如:

    <LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/parent">

<View
android:layout_width="fill_parent"
android:layout_height="5dp"
android:background="@drawable/gradient" />

<!-- Your other child views -->


<View
android:layout_width="fill_parent"
android:layout_height="5dp"
android:background="@drawable/gradient" />

</LinearLayout>

您的 gradient.xml 文件将包含以下内容:

<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient android:startColor="#FFFFFF" android:endColor="#000000" android:angle="90"/>
</shape>

您可以为父布局指定蓝色背景色。

你基本上会得到这样的东西:

enter image description here

[编辑]

您可以创建两个可绘制对象 - gradient_top.xmlgradient_bottom.xml 以获得正确的角度

关于android - 具有纯色背景和顶部+底部内部阴影的 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20442767/

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