gpt4 book ai didi

安卓。在图像上添加文字效果

转载 作者:太空宇宙 更新时间:2023-11-03 12:48:36 25 4
gpt4 key购买 nike

世界!我是一名学生,我正在开发一个关于我的国家的 Android 应用程序。我注意到应用程序中的布局很漂亮。 A text is over image at the bottom with background gradient

在这张图片中,textviews 放置在图片的底部,背景很漂亮(有点渐变)我想知道您是否可以帮助我弄清楚如何去做或指明方向。我现在只有这个:行.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>

谢谢!

最佳答案

您可以做的,实际上是使用 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 - 请参阅 documentation更多属性。

我可能会将副标题文本颜色更改为与标题文本颜色相同的颜色。

关于安卓。在图像上添加文字效果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36845169/

25 4 0
文章推荐: python - 我如何去一个随机的网站? - Python
文章推荐: ruby-on-rails - 如何从 Rails 中将 https ://mydomain. com 之类的 url 重定向到 https ://www. mydomain.com
文章推荐: python - 使用正则表达式提取字符串
文章推荐: c# - Json转换器 : Return a single object or a List based on inbound JSON