Android TextView背景透明覆盖在ImageView上

4
请告诉我如何按照图像添加透明背景的textview覆盖imageview。详细说明是,我想在imageview上添加两个textview,一个textview是标题,另一个是描述,而且背景是透明的。请帮忙。 enter image description here
4个回答

8
我认为您应该在布局的xml中使用合并标记。例如,合并示例

请发布答案的相关部分,而不仅仅是链接。 - UserK

3
一种可能的方法是:将Framelayout作为根视图,然后添加文本视图和图像视图,如下所示。
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<ImageView  
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 

    android:scaleType="center"
    android:src="@drawable/golden_gate" />

<TextView
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginBottom="20dip"
    android:layout_gravity="center_horizontal|bottom"

    android:padding="12dip"

    android:background="#AA000000"
    android:textColor="#ffffffff"

    android:text="Golden Gate" />

 </FrameLayout>

请查看以下链接以了解有关Android布局优化的技巧:http://android-developers.blogspot.ru/2009/03/android-layout-tricks-3-optimize-by.html - Milon
完美。对我起作用了! - hetsgandhi

1
你可以使用FrameLayout作为容器,并将TextView覆盖在ImageView上,并分配一个具有较低alpha通道#AARRGGBB的背景。

0

你可以将图片设置为你的布局父项(如RelativeLayout)的背景,然后在第一个布局底部放置另一个背景透明的布局。 接着,我们将你的textView放入第二个布局中。


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