0
我嘗試使用imageview滾動視圖完全像標識測驗應用程序中的滾動視圖。在JAVA代碼中添加ImageViews到滾動視圖
我創建了一個滾動視圖的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視圖時編寫了特定的寬度和高度,我可以在屏幕中看到視圖,但不能作爲滾動視圖,否則不起作用。
我們需要一些更多的上下文;什麼是Level1Draw對象的寬度和高度設置爲?你是什麼意思,你可以在屏幕上看到它,但不是一個滾動視圖? – Blaskovicz
我添加了Level1Draw類 – user1447655