【问题标题】:TextView on top of StateListDrawableStateListDrawable 之上的 TextView
【发布时间】:2013-04-04 21:14:57
【问题描述】:

我试图让我的 TextViews 和 ImageView 显示在我添加了 StateListDrawable 的 LinearLayout 之上。我这样创建按钮:

    protected StateListDrawable generateButton(String[] colors, String[] selectColors, String strokeColor, int strokewidth)
{
    int[] iColors = CurrentTheme.getIntColorArrayFromStringArray(colors);

    GradientDrawable gd = new GradientDrawable(Orientation.TL_BR, iColors);
    gd.setCornerRadius(10);
    gd.setStroke(strokewidth, Color.parseColor(strokeColor));

    int[] iSelectColors = CurrentTheme.getIntColorArrayFromStringArray(selectColors);

    GradientDrawable sgd = new GradientDrawable(Orientation.TL_BR, iSelectColors);
    sgd.setCornerRadius(10);
    sgd.setStroke(strokewidth, Color.parseColor(strokeColor));

    StateListDrawable slDrawable = new StateListDrawable();
    slDrawable.addState(new int[] { android.R.attr.state_pressed }, sgd);
    slDrawable.addState(StateSet.WILD_CARD, gd);    

    return slDrawable;
}

在我的活动中,我将这个可绘制对象添加到这样的线性布局中:

_topMenuButton.setBackgroundDrawable(_theme.getPrimaryButtonDrawable());

布局包含在我的 Activity 的内容视图中的以下行中:

<include layout="@layout/inc_button_menu" android:id="@+id/second_menu_button" />

其中又包含一个 LinearLayout,其中包含一个 ImageView 和两个 TextView。

当我尝试从 LinearLayout(我在我的 Activity 中添加 StateListDrawable)获取 TextViews 并向其中添加 Text 时,文本不会显示。 ImageView 也是如此。我不确定如何让这些视图显示出来。

非常感谢任何帮助。

【问题讨论】:

    标签: android textview imageview statelistdrawable


    【解决方案1】:

    原来不是后面的代码,而是包含的布局中的代码。由于该代码之前将布局文件用作可绘制文件,因此我认为它不是此代码。问题是我在其中一项上使用了 android:weight="1"。

    【讨论】:

      猜你喜欢
      • 2023-03-27
      • 1970-01-01
      • 2020-02-23
      • 2014-03-25
      • 1970-01-01
      • 1970-01-01
      • 2017-11-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多