gpt4 book ai didi

安卓渐变背景

转载 作者:行者123 更新时间:2023-11-30 01:14:54 24 4
gpt4 key购买 nike

我需要实现这样的东西,底部有黑色渐变效果 Image

我使用了下面的代码activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_marginBottom="5dp"
android:background="@drawable/my_custom_drawable"
xmlns:android="http://schemas.android.com/apk/res/android">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/dead"
android:scaleType="fitXY"
android:id="@+id/place_image"
/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:background="#AA000000">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Medeu"
android:id="@+id/place_id"
android:layout_marginLeft="20dp"
android:layout_marginTop="2dp"
android:textSize="18sp"
android:textColor="#ffffff"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Almaty region"
android:textColor="#ffffff"
android:layout_marginLeft="20dp"
android:layout_below="@+id/place_id"
android:textSize="12sp"
android:id="@+id/place_id_sub"

/>
</RelativeLayout>
</RelativeLayout>

和 my_custom_drawable.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:startColor="#00000000"
android:endColor="#80000000"
android:angle="270"
android:dither="true"
/>
</shape>

我是这样的

Image 2

为什么我没有得到第一张图片的效果,我引用了其他问题的几个热门答案

最佳答案

问题是您的 ImageView 覆盖了您设置背景的 RelativeLayout,因此它不可见。

ImageView 上方添加一个具有所需背景的 View 而不是设置 RelativeLayout 的背景应该可行:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_marginBottom="5dp">

<ImageView
android:id="@+id/place_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:src="@drawable/dead" />

<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/my_custom_drawable" />

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true">

<TextView
android:id="@+id/place_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="2dp"
android:text="Medeu"
android:textColor="#ffffff"
android:textSize="18sp" />

<TextView
android:id="@+id/place_id_sub"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/place_id"
android:layout_marginLeft="20dp"
android:text="Almaty region"
android:textColor="#ffffff"
android:textSize="12sp" />
</RelativeLayout>
</RelativeLayout>

关于安卓渐变背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37996959/

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