0

APIレベル7以上で開発しているため、setAlpha(float)使用できません。そのため、特定の子要素をすべてトラバースViewGroupし、要素がほぼ透明になるようにアルファを設定する方法を見つけようとするメソッドを実装しました。ListView残念ながら、とそのアイテムを透明にする方法を思い付くことができません。どうすれば続行できますか?

私の方法:

public void enableDisableViewGroup(ViewGroup viewGroup, boolean enabled) {
    int childCount = viewGroup.getChildCount();
    for (int i = 0; i < childCount; i++) {
        View view = viewGroup.getChildAt(i);

        view.setEnabled(enabled);
        if (!enabled) {
            if (view instanceof TextView) {
                int curColor = ((TextView) view).getCurrentTextColor();
                int myColor = Color.argb(ALPHA_NUM, Color.red(curColor),
                        Color.green(curColor),
                        Color.blue(curColor));

                ((TextView) view).setTextColor(myColor);
            } else if (view instanceof ImageView) {
                ((ImageView) view).setAlpha(ALPHA_NUM);
            } else if (view instanceof ListView) {
                // How do I set the text color of the subitems in this listview?
            } else {
                try {
                    Paint currentBackgroundPaint =
                            ((PaintDrawable) view.getBackground()).getPaint();
                    int curColor = currentBackgroundPaint.getColor();
                    int myColor = Color.argb(ALPHA_NUM, Color.red(curColor),
                            Color.green(curColor), Color.blue(curColor));
                    view.setBackgroundColor(myColor);
                } catch (NullPointerException e) {
                    Log.d("viewNotFound", "View " + view.getId() + " not found..");
                    e.getStackTrace();
                }
            }
            if (view instanceof ViewGroup) {
                enableDisableViewGroup((ViewGroup) view, enabled);
            }
        }
    }
}
4

1 に答える 1

0

これを行の XML に直接設定するオプションはありますListViewか?

たとえば、レイアウトがLinearLayout

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@android:color/transparent">

    <!-- stuff -->
</LinearLayout>

あなたの設定はわかりませんが、本当にListView透明にしたい場合は、このようにプログラムで設定できるかもしれません。

ListView listView = (ListView) view;
listView.setBackgroundColor(android.R.color.transparent);

デフォルトの色android.R.color.transparentは次のとおりです。

<!-- Fully transparent, equivalent to 0x00000000 -->
<color name="transparent">#00000000</color>

この場合、ListView行を XML で透過的に設定する必要があります。

View行内の の透明度を制御したい場合は、カスタムを作成してそこで処理ListViewするのが最善の策です。ArrayAdapter

于 2013-02-25T17:39:45.623 に答える