2

ImageButton のようなボタンを作成しようとしています。そして厄介な問題に直面しました。setImageBitmap を適用した後、ImageView では何も起こりません。ビットマップ自体にイメージが含まれています (null ではありません)。さらに、同じ関数 ( ImageManager.getImage("menu", id) ) は、ListView アダプターにビットマップを含める必要があるプログラムの他の場所で使用していますが、正常に動作します。

for( int i = 0; i < MenuArray.size(); i++)
        {
            View buttonView = MainActivity.getLayoutInflater().inflate(R.layout.top_button, MenuLayout, false);
            buttons[i] = (ImageView) buttonView.findViewById(R.id.imageForeground);
            ImageView imageBackground = (ImageView) buttonView.findViewById(R.id.imageBackground);
            imageBackground.setImageBitmap(ImageManager.getImage("menu", MenuArray.get(i).id));

            MenuLayout.addView(buttonView);
        }

XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="40dp"
    android:layout_height="40dp"
    android:layout_margin="2dp" >
    <ImageView
        android:id="@+id/imageBackground"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:src="@drawable/cart_item" />

    <ImageView
        android:id="@+id/imageForeground"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:src="@drawable/button_selector" />
</RelativeLayout>
4

0 に答える 0