0
我有一個具有繪製位圖的自定義視圖的應用程序。我想在位圖頂部的視圖中放置一個按鈕。該活動的setContentView設置爲自定義視圖類,因此我無法從main.xml充氣按鈕。我如何解決這個問題?是否有可能在視圖類中以編程方式創建按鈕,然後附加一個偵聽器?如何將按鈕添加到顯示位圖的自定義視圖
公共類Jjilapp延伸活動{
private static final String TAG = "*********jjil";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.e(TAG, "***********inside oncreate about to set contentview = ");
setContentView(new TouchView(this));
}
class TouchView extends View{
public TouchView(Context context) {
super(context);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
.......
BitmapFactory.Options bfo = new BitmapFactory.Options();
bfo.inSampleSize = 1;
bm = BitmapFactory.decodeByteArray(imageArray, 0, imageArray.length, bfo);
bgr = Bitmap.createBitmap(bm.getWidth(), bm.getHeight(), bm.getConfig());
bgr = bm.copy(bm.getConfig(), true);
}// end of class touchView
@Override
public void onDraw(Canvas canvas){
super.onDraw(canvas);
canvas.drawBitmap(bgr, 0, 0, null);
canvas.drawCircle(centreX, centreY, radius,pTouch);
}//end of onDraw
}
}