画像を端末内から取得し、写真一覧を表示する画面を作成しているのですが、スクロールを行うことが出来ません。
下記のl.addView(new MyView(this, test));を実行してもMyViewのonDrawが実行されないので何も表示されません。
ScrollViewを使用せずに表示を試みると正常に動作します。
原因が全く分からず、二日間ずっと悩んでます...。
皆さんの回答をお待ちしています。
どうかよろしくお願い致します。
Java
1public class Tab3Activity extends Activity{ 2 @Override 3 public void onCreate(Bundle savedInstanceState){ 4 super.onCreate(savedInstanceState); 5 6 LinearLayout l = new LinearLayout(this); 7 l.setOrientation(LinearLayout.VERTICAL); 8 9 ScrollView sv = new ScrollView(this); 10 setContentView(sv); 11 sv.addView(l); 12 13 14 Cursor cursor = getContentResolver().query( 15 MediaStore.Images.Media.EXTERNAL_CONTENT_URI, 16 null, 17 null, 18 null, 19 null 20 ); 21 cursor.moveToFirst(); 22 23 int cnt = 0; 24 ArrayList<Bitmap> test = new ArrayList<Bitmap>(); 25 BitmapFactory.Options options = new BitmapFactory.Options(); 26 options.inSampleSize = 35; 27 do { 28 test.add(BitmapFactory.decodeFile(cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.DATA)), options)); 29 cnt++; 30 cursor.moveToNext(); 31 }while(cnt < 20); 32 cnt = 0; 33 34 l.addView(new MyView(this, test)); 35 } 36}
Java
1//Custom View 2public class MyView extends View { 3 Paint paint = new Paint(); 4 ArrayList<Bitmap> mBmps; 5 6 public MyView(Context context, ArrayList<Bitmap> bmps) { 7 super(context); 8 mBmps = new ArrayList<Bitmap>(bmps); 9 setWillNotDraw(false); 10 } 11 12 @Override 13 public void onDraw(Canvas canvas){ 14 int height = 10; 15 16 for(int i = 0; i < mBmps.size(); i++){ 17 if(i % 2 == 0){ 18 canvas.drawBitmap(mBmps.get(i), 10, height, paint); 19 height += 100; 20 }else{ 21 canvas.drawBitmap(mBmps.get(i), 200, height, paint); 22 } 23 } 24 } 25}
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/06/26 01:18