安卓。如何在图片上添加带有特效的文字

5

世界,我是一名学生,正在开发一款有关我的国家的Android应用程序。我注意到一个应用程序中有一个漂亮的布局。 底部带背景渐变的文本图像

在这张图片中,文本视图被放置在带有美丽背景(类似渐变)的图像底部。 我想知道如何实现它或者指导方向。 目前我只有以下内容: row.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="200dp"
    android:layout_marginBottom="5dp"
    xmlns:android="http://schemas.android.com/apk/res/android">
        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:src="@drawable/medeobase"
            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="@color/colorWhite"/>
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Almaty region"
                android:textColor="@color/colorPrimary"
                android:layout_marginLeft="20dp"
                android:layout_below="@+id/place_id"
                android:textSize="12sp"
                android:id="@+id/place_id_sub"

                />
        </RelativeLayout>
    </RelativeLayout>

谢谢!

1个回答

10
你可以使用GradientDrawable作为RelativeLayout的背景,以此来装饰TextView。渐变效果可以如下所示:

my_custom_drawable.xml:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <gradient
        android:angle="90"
        android:endColor="@android:color/transparent"
        android:startColor="@android:color/black" />
</shape>

然后将您的RelativeLayout的背景颜色替换为渐变,如下所示:

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:layout_alignParentBottom="true"
    android:background="@drawable/my_custom_gradient.xml">

这将导致以下结果:

Gradient

你需要在GradientDrawable中尝试不同的颜色,以满足你的需求。当然,我无法告诉你哪种颜色适合你的需求。
你还可以添加一个centerColor - 更多属性请参见文档
我会将副标题的文本颜色更改为与标题文本颜色相同的颜色。

非常感谢您!它帮助了我!很抱歉我不能给您点赞,因为我的评分不够。 - Zhadyrassyn Daniyar
@ZhadyrassynDaniyar 没问题 :-) 我认为你仍然可以接受它作为答案,即使没有声望 :-) - Darwind

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接