1

我有一个带有 imageview 和 textview 的布局。

我想要这样的东西:

在此处输入图像描述

带有标题的图像视图,但我希望标题的布局是透明的,以便在背景中显示图像视图。

这是我的布局代码:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="230dp"
        android:layout_marginBottom="3dp" >

        <ImageView
            android:id="@+id/imgimg"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:src="@drawable/ic_action_picture"
            android:scaleType="centerCrop" />

        <TextView
            android:id="@+id/titlenew"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:text="TextView"
            android:textColor="@color/blanc" />

    </RelativeLayout>

</LinearLayout>
4

4 回答 4

4

尝试这个

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="230dp"
    android:layout_marginBottom="3dp" >

    <ImageView
        android:id="@+id/imgimg"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:scaleType="centerCrop"
        android:src="@drawable/ic_launcher" />

    <TextView
        android:id="@+id/titlenew"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:background="#80000000"
        android:gravity="center"
        android:padding="5dp"
        android:text="TextView"
        android:textColor="#fff" />
</RelativeLayout>

在此处输入图像描述

于 2013-08-19T08:49:28.853 回答
1

尝试设置android:background="@android:color/transparent"TextView

于 2013-08-19T08:25:54.000 回答
0

干得好 :)

 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
         >


            <ImageView
                android:id="@+id/imgimg"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:src="@drawable/ic_action_picture"
                android:scaleType="centerCrop" />

            <TextView
                android:id="@+id/titlenew"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="TextView"
                android:gravity="bottom" 
                android:paddingTop="5dp"
                android:paddingBottom="5dp"
                android:layout_gravity="bottom"
                android:background="#99000000"
                android:textColor="@color/blanc" />


    </FrameLayout>
于 2013-08-19T08:42:03.843 回答
0

您可以将其添加到 textview:

android:background="#00000000"

如果您想控制背景的透明度,请使用 alpha 值,如下所示:

android:background="#CCFF0000"
于 2013-08-19T08:26:47.717 回答