我尝试使用 imageview 制作滚动视图,就像徽标测验应用程序中的滚动视图一样。
我创建了一个带有滚动视图的 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 视图时写了一个特定的宽度和高度,我可以在屏幕上看到该视图,但不能作为滚动视图,否则它不起作用。