0

ロゴクイズアプリのスクロールビューとまったく同じように、イメージビューでスクロールビューを作成しようとしています。

スクロールビューで XML ファイルを作成します。

<ScrollView
    android:id="@+id/scrollView1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/beige"
    > 
    <LinearLayout
        android:id="@+id/layout_level1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">
    </LinearLayout>
</ScrollView>

そして私がこれを書いたより:

public class Level1 extends Activity {

Level1Draw L1;  
LinearLayout l;
ScrollView s;


@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    L1 = new Level1Draw(this);
    setContentView(R.layout.level1);


    l = (LinearLayout) findViewById(R.id.layout_level1);


    l.addView(L1);


}

これは Level1Draw クラスです:

private class Level1Draw extends View {

        Bitmap[][] logo_1 = {{BitmapFactory.decodeResource(getResources(), R.drawable.cellcom),BitmapFactory.decodeResource(getResources(), R.drawable.channel1),BitmapFactory.decodeResource(getResources(), R.drawable.doctor_gav)},
                {BitmapFactory.decodeResource(getResources(), R.drawable.golfnew),BitmapFactory.decodeResource(getResources(), R.drawable.globes_only_logo_acrobat),BitmapFactory.decodeResource(getResources(), R.drawable.foxgroup3)},
                {BitmapFactory.decodeResource(getResources(), R.drawable.hando),BitmapFactory.decodeResource(getResources(), R.drawable.hafenix),BitmapFactory.decodeResource(getResources(), R.drawable.haaretz)},
                {BitmapFactory.decodeResource(getResources(), R.drawable.laisha),BitmapFactory.decodeResource(getResources(), R.drawable.jerusalempostred),BitmapFactory.decodeResource(getResources(), R.drawable.hop)},
                {BitmapFactory.decodeResource(getResources(), R.drawable.maariv),BitmapFactory.decodeResource(getResources(), R.drawable.logo),BitmapFactory.decodeResource(getResources(), R.drawable.logodelta)},
                {BitmapFactory.decodeResource(getResources(), R.drawable.renuar),BitmapFactory.decodeResource(getResources(), R.drawable.ravbariah),BitmapFactory.decodeResource(getResources(), R.drawable.pelephone)},
                {BitmapFactory.decodeResource(getResources(), R.drawable.shilav),BitmapFactory.decodeResource(getResources(), R.drawable.sano),BitmapFactory.decodeResource(getResources(), R.drawable.reshet_tv)},
                {BitmapFactory.decodeResource(getResources(), R.drawable.steimatzky),BitmapFactory.decodeResource(getResources(), R.drawable.srigamish),BitmapFactory.decodeResource(getResources(), R.drawable.sport5)},
                {BitmapFactory.decodeResource(getResources(), R.drawable.tambur),BitmapFactory.decodeResource(getResources(), R.drawable.supersal),BitmapFactory.decodeResource(getResources(), R.drawable.superpharm)},
                {BitmapFactory.decodeResource(getResources(), R.drawable.yediot),BitmapFactory.decodeResource(getResources(), R.drawable.walla),BitmapFactory.decodeResource(getResources(), R.drawable.tzometsfarim)},
                };

        public Level1Draw(Context context) {
            // TODO Auto-generated constructor stub
            super(context);


        }



        @Override
        protected void onDraw(Canvas canvas) {  
            // TODO Auto-generated method stub
            super.onDraw(canvas);
            for(int i=0;i<10;i++){
                for(int j=0;j<3;j++){
            canvas.drawBitmap(logo_1[i][j], 60*(j+1)+80*j, 60*(i+1)+80*i, null);
                }
            }

        }




    }

L1ビューを追加するときに特定の幅と高さを書くと、画面にはビューが表示されますが、スクロールビューとしては表示されません。そうしないと機能しません。

4

1 に答える 1

0

あなたの「Level1Draw」クラスにはonMeasureが実装されていないため、必要なサイズについて親に何を伝えるべきかわかりません。また、作成時にlayoutParamsもありません。

要するに、カスタム ビューは単にペイントするよりもはるかに手間がかかります。

いずれにせよ、それをラップする scrollView を持つ linearLayout の代わりに、その中に imageViews を持つ listView を使用してみませんか? それははるかに高速で、簡単で、メモリ効率が良いです (100 個の imageView を取得するために何をするか想像してみてください...)。

詳細については、次のビデオをご覧ください。

http://www.youtube.com/watch?v=wDBM6wVEO70

于 2012-06-10T22:38:57.160 に答える