【问题标题】:Transparent TextView background in FrameLayoutFrameLayout中的透明TextView背景
【发布时间】:2012-04-30 19:16:43
【问题描述】:

我在 FrameLayout 中的 ImageView 上放置了一个 TextView。我已经为 TextView 尝试了各种 android:background 组合,但总是得到一个透明的灰色背景。我想要一个透明的背景。 android:background 属性似乎被忽略了。

<HorizontalScrollView
    android:id="@+id/categories_horizontal_scrollview"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:paddingBottom="25dip">
    <LinearLayout
        android:id="@+id/categories_linear_layout"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <FrameLayout
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content">
        <ImageView  
            android:layout_width="fill_parent" 
            android:layout_height="fill_parent" 
            android:id="@+id/photos_imageview"
            android:scaleType="center"
            android:src="@drawable/photos_ipad" />
        <TextView
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content" 
            android:id="@+id/photos_text"
            android:layout_marginBottom="10dip"
            android:layout_gravity="center_horizontal|bottom"
            android:padding="3dip" 
            android:background="#00000000"
            android:textColor="#ffffffff"
            android:textSize="20dip" 
            />
        </FrameLayout>
              .
              .

【问题讨论】:

  • 如果你想在文本视图后面使用图像,为什么不把图像设置为文本视图的背景呢?使用 android:backround="@drawable/photos_ipad"
  • 另外,尝试使用 Android 的内置颜色作为文本视图上的透明背景 (android:background="@android:color/transparent")
  • 您的 textview 不在 imageview 上...
  • 我试过 android:background="android:color/transparent",它没有用。我做框架布局的原因是我需要文本位于图像的底部。
  • 如果它不起作用,究竟发生了什么?它可能与您的滚动视图有关。我会先制作一个只有框架布局和 imageview/textview 的测试应用程序。看看透明度是否有效。然后添加线性布局。然后是滚动视图。看看你能不能找出问题出在哪里。

标签: android background textview imageview android-framelayout


【解决方案1】:

使用这个:

TextView tv;
tv.setBackgroundColor(0xXX??????);

其中 XX - [00;FF] - 透明度指标。 ??? - 一些数字(原色)

希望对您有所帮助)))

【讨论】:

  • 您可以在上面看到他已经将 android:background 设置为 #00000000,这与您的建议相同,除了以编程方式而不是在 XML 中。
  • 是的,我同意应该这样做。但我认为问题不在于 setBackgroundColor 调用。我认为它在某个地方是他的布局层次结构。
【解决方案2】:

正如 Brayden 指出的那样,布局存在问题。我最终将 ImageView 和 TextView 作为单个资源放入 FrameLayout 中,然后在需要的地方动态添加。

【讨论】:

    【解决方案3】:

    我们使用这样的代码来实现透明背景。

    android:background="@android:color/transparent"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-07-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-15
      • 2011-03-08
      • 1970-01-01
      • 2015-03-26
      相关资源
      最近更新 更多