【问题标题】:My gradients don't show up in my Android project我的渐变没有出现在我的 Android 项目中
【发布时间】:2010-11-02 06:13:39
【问题描述】:

我是 Android 平台的新手,我正在开发一个应用程序,它的主要活动是 正在使用对话框主题。

我几乎按照我想要的方式设置了 ui,但渐变似乎对我不起作用。 我尝试了渐变标题栏、视图、布局、textView 等,但在每种情况下都不会显示渐变。 (到目前为止,我只在模拟器上测试过它)。

我的可绘制 xml 如下所示:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
  <gradient
      android:startColor="#00000000"
      android:centerColor="#FFFFFFFF"
      android:endColor="#00000000"
      android:angle="90" />
</shape>

我使用以下方法将背景设置为几个元素,但它从未出现:

android:background="@drawable/gradient_bg"

我尝试了不同的颜色和角度等,但无济于事。

如果我执行以下操作,但我更喜欢在 xml 中执行此操作。

GradientDrawable grad = new GradientDrawable(
      Orientation.TOP_BOTTOM,
      new int[] {Color.RED, Color.YELLOW}
    );
    this.getWindow().setBackgroundDrawable(grad);

有人可以帮忙吗? 谢谢。

【问题讨论】:

    标签: android dialog gradient


    【解决方案1】:

    尝试在整个渐变中设置不透明的颜色。

    例如,将#FF000000 用于黑色。前两个十六进制数字是 alpha 值。

    【讨论】:

      【解决方案2】:

      你的代码是:

      <shape xmlns:android="http://schemas.android.com/apk/res/android"
          android:shape="rectangle">
        <gradient
            android:startColor="#00000000"
            android:centerColor="#FFFFFFFF"
            android:endColor="#00000000"
            android:angle="90" />
      </shape>
      

      在 Android HTC Hero 手机上运行良好并且显示正确!可能是模拟器上没有显示梯度效果的情况。

      【讨论】:

        【解决方案3】:

        谢谢。我已经确定它可以在实际设备上运行,所以它一定是模拟器问题。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2022-01-16
          • 1970-01-01
          • 1970-01-01
          • 2012-10-03
          • 1970-01-01
          • 2014-01-18
          相关资源
          最近更新 更多