1
這是我的代碼。我得到空值。我試圖找出解決方案,因爲早晨,我已經創建了使用xml文件的佈局,然後我得到了位圖的視圖,但我想它動態和I have created layout programatically
見下面的代碼。 我的看法是出現罰款,但仍getting getDrawingCache() null bitmap
從android的getDrawingCache()獲取空位圖
LinearLayout mainlayout = new LinearLayout(getApplicationContext());
mainlayout.setOrientation(LinearLayout.VERTICAL);
mainlayout.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
ImageView top= new ImageView(getApplicationContext());
ImageView bot= new ImageView(getApplicationContext());
Bitmap bottomImage = BitmapFactory.decodeResource(getResources(), R.drawable.collagebot);
Bitmap topImage =BitmapFactory.decodeResource(getResources(), R.drawable.collagetop);
top.setImageBitmap(topImage);
bot.setImageBitmap(bottomImage);
LinearLayout midLayout = new LinearLayout(getApplicationContext());
midLayout.setOrientation(LinearLayout.HORIZONTAL);
midLayout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
Bitmap midlaybg =BitmapFactory.decodeResource(getResources(), R.drawable.bg);
Drawable middrow = new BitmapDrawable(getResources(),midlaybg);
midLayout.setBackground(middrow);
ImageView right= new ImageView(getApplicationContext());
ImageView left= new ImageView(getApplicationContext());
Bitmap rightImage = BitmapFactory.decodeResource(getResources(), R.drawable.fb);
Bitmap leftImage =BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
Drawable rightdrow = new BitmapDrawable(getResources(),rightImage);
Drawable leftdrow = new BitmapDrawable(getResources(),leftImage);
right.setBackground(rightdrow);
left.setBackground(leftdrow);
right.setLayoutParams(new LayoutParams(150,150));
left.setLayoutParams(new LayoutParams(150,150));
left.setLayoutParams(new LinearLayout.LayoutParams(150, 150, 10));
midLayout.setPadding(50, 0, 0, 0);
midLayout.addView(right);
midLayout.addView(left);
mainlayout.addView(top);
mainlayout.addView(midLayout);
mainlayout.addView(bot);
Bitmap mainlaybg =BitmapFactory.decodeResource(getResources(), R.drawable.bg);
Drawable maindrow = new BitmapDrawable(getResources(),mainlaybg);
mainlayout.setBackground(maindrow);
mainlayout.setDrawingCacheEnabled(true);
mainlayout.buildDrawingCache();
// setContentView(mainlayout); // i dont want to setContentView
Log.e("ceche",""+mainlayout.getDrawingCache());// here i am getting null bitmap of mainlayout view
Bitmap imgb=mainlayout.getDrawingCache();
謝謝佐勒菲卡爾Chandio其做工精細.. – addy