80,351
社区成员
发帖
与我相关
我的任务
分享
public class AndTest extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new myview(this).layout);
}
public class myview extends View {
Bitmap bmp;
Bitmap bmp2;
TextView tv;
LinearLayout layout;
public myview(Context context) {
super(context);
// TODO Auto-generated constructor stub
Resources res=context.getResources();
bmp=BitmapFactory.decodeResource(res,R.drawable.icon);
bmp2=BitmapFactory.decodeResource(res,R.drawable.icon);
//Resources resources = getContext().getResources();
//Drawable btnDrawable = resources.getDrawable(R.drawable.bitmap1);
//Layout.setBackgroundDrawable(btnDrawable);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.FILL_PARENT,
LinearLayout.LayoutParams.FILL_PARENT);
LinearLayout.LayoutParams lp1 = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.FILL_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
layout = new LinearLayout(AndTest.this);
layout.setLayoutParams(lp);
tv = new TextView(AndTest.this);
tv.setText("Hello world!\nYou are welcome!");
layout.addView(tv, lp1);
}
@Override
protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
super.onDraw(canvas);
canvas.drawColor(Color.WHITE);
canvas.drawBitmap(bmp2, 0, 0,new Paint());
canvas.drawBitmap(bmp, 40, 130,new Paint());
}
}
}