3

我有一个使用图像视图的图像,在图像的底部,我想要一个半透明的视图(黑色),其中将包含一些文本视图。像这样的东西

在此处输入图像描述

我已经在图像上放置了文字,但现在我被困在获得黑色背景的视图上。我试过了

 <TextView 
 android:background="@color/lightGrey"
 android:text="Swiss Chalet - Play for a chance to win free app!"/>

但是它只为文本提供灰色背景。任何人都知道我怎样才能做到这一点?

4

5 回答 5

6

在你的背景中尝试这样的事情

android:background="#80000000"

您可以在此处找到有关设置透明度的更多信息

于 2013-10-22T17:49:49.573 回答
6

在您的 xml 中,使用

android:alpha=".4"

这将设置视图的 alpha 值。Alpha 是透明度。您可以调整以增加或减少透明度。


在不知道您是如何实现布局的情况下,这是在黑暗中拍摄的,但它可能会有所帮助。

<TextView
    android:id="@+id/your_id_name"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:text="Your text"
    android:background:"@color/your_color"/>
于 2013-10-22T17:50:36.720 回答
2

在您的 colors.xml 文件中(或您定义颜色“lightGrey”的任何位置),您可以通过在颜色的十六进制代码前面添加两位数字(格式为 AARRGGBB)来指定 alpha 通道。

例如,如果您的 lightGrey 颜色是 #555555,则将其列为

<color name="lightGrey">#CC55555</color>

而是将颜色设为 20% 透明和 80% 不透明。00 表示完全不透明度(0% 透明度),FF 对应于 100% 透明度(不可见)。希望这可以帮助!

于 2013-10-22T17:55:30.920 回答
0

你可以这样做,

<FrameLayout
  android:layout_width="match_parent"
  android:layout_height="match_parent">
    <FrameLayout
       android:layout_width="match_parent"
       android:layout_height="match_parent"
       android:alpha="0.4"
       android:background="@android:color/black"/>

   <TextView 
    android:background="@color/lightGrey"
    android:text="Swiss Chalet - Play for a chance to win free app!"/>
</FrameLayout>
于 2013-10-22T18:01:11.013 回答
-1

尝试这个:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/icmsLrnArtListItem"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@android:color/white"
    android:layout_margin="3dp"
    android:padding="5dp" >

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="5dp" >

        <ImageView
            android:id="@+id/icmsImageThumb"
            android:layout_width="match_parent"
            android:layout_height="180dp"
            android:src="@drawable/ic_launcher"
            android:scaleType="fitXY" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="top"
            android:background="@android:color/darker_gray"
            android:textColor="@android:color/black"
            android:text="Image Top text"
            android:gravity="center"
            android:textStyle="bold" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            android:background="@android:color/darker_gray"
            android:ellipsize="end"
            android:maxLines="2"
            android:text="Image Bottom text"
            android:textColor="@android:color/black"
            android:shadowColor="#FFFFFF"
            android:gravity="center"
            android:shadowDx="2"
            android:textStyle="bold"
            android:shadowDy="2"
            android:shadowRadius="2" />
    </FrameLayout>

</LinearLayout>
于 2013-10-23T03:46:16.683 回答