2

私は過去 6 時間にわたってこの問題をデバッグしており、問題を最も単純なケース (ロジックの大部分を取り除いたもの) に単純化しました。ビューで 2 つの (ニワトリ) 画像を重ね合わせようとしています。

私は最後の答えを含む多くの例に従いました: Draw multiple bitmap on a view in android

私の活動は次のようになります。

public class FinalDisplay extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_final_display);

    LinearLayout layout = (LinearLayout) findViewById(R.id.activity_final_display);

    ImageView iv = new ImageView(this);
    iv.setBackgroundResource(R.drawable.images);
    layout.addView(iv);

    ImageView iv2 = new ImageView(this);
    iv.setBackgroundResource(R.drawable.images);
    layout.addView(iv2);

}

R.drawable.images は、私がインターネットから取得し、drawable フォルダーに配置したニワトリの画像です。

http://images3.wikia.nocookie.net/__cb20130606165308/animalcrossing/images/4/41/Chicken.jpg

私のxmlページは次のようになります

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_final_display"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".FinalDisplay" >

ただし、ニワトリは 1 羽しか登場しません。どんな助けでも大歓迎です。

4

2 に答える 2

1
ImageView iv = new ImageView(this);
iv.setBackgroundResource(R.drawable.images);
layout.addView(iv);

ImageView iv2 = new ImageView(this);
iv2.setBackgroundResource(R.drawable.images);
layout.addView(iv2);

それを試してみてください

于 2013-09-19T04:05:44.940 に答える