Can someone tell why my code for creating imagebutton is not working and provide a reference for such issues

Wednesday, November 4, 2015

public class SampleActivity extends AppCompatActivity {



@Override



public void onCreate(Bundle savedInstanceState)

{
super.onCreate(savedInstanceState);
Keypaint view = new Keypaint(this);
setContentView(view);
}

public class Keypaint extends View
{
Paint p;
protected void onDraw(Canvas canvas)
{
super.onDraw(canvas);
Bitmap bit = BitmapFactory.decodeResource(getResources(),R.drawable.bg);
//canvas.drawBitmap(bit,0,0,null);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
ImageButton btn = new ImageButton(getContext());
btn.setImageBitmap(bit);

btn.setLayoutParams(params);
// p=new Paint();
//Bitmap b1=BitmapFactory.decodeResource(getResources(), R.drawable.bg);
//canvas.drawBitmap(b1, 0, 0, null);
}

public Keypaint(Context context)
{
super(context);
}
}


}

0 comments:

Post a Comment