Add ImageViews to ScrollView in JAVA code

paulvandyk

New Member
I try to make a scrollview with imageview exactly like the scrollview in the logos quiz app.I create an XML file with a scrollview.\[quote\] \[code\]<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>\[/code\] \[/quote\]and than i wrote this: \[code\]public class Level1 extends Activity {Level1Draw L1; LinearLayout l;ScrollView s;@Overrideprotected 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);}\[/code\]this is the Level1Draw class:\[code\]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[j], 60*(j+1)+80*j, 60*(i+1)+80*i, null); } } } }\[/code\]if i write a specific width and height when i add the L1 view, i can see the view in the screen but not as a scrollview, otherwise it doesn't work.
 
Back
Top