如何在android中创建多层视图,具有图像和颜色?

时间:2017-05-20 17:08:57

标签: android view textview imageview setbackground

我想在前台创建一个带TextView的视图,并且可以在背景中设置图像和颜色。 这是我期待的观点图像。 enter image description here enter image description here enter image description here enter image description here

我尝试使用setBackgroundView()方法进行设置,但它接受图像或颜色。 我怎样才能达到这个效果? 提前谢谢。

1 个答案:

答案 0 :(得分:0)

使用FrameLayout

替换字符串,大小和可绘制内容以匹配您的内容。

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/purple_50">

    <ImageView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:src="@drawable/pattern"
    />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:padding="@dimen/widget_margin"
        android:text="@string/content"
        android:gravity="center"
        android:textSize="@dimen/text_content"/>
</FrameLayout>
相关问题