简体   繁体   中英

Resize checkbox image in Android programmatically

I want to resize the image of the CheckBox programmatically, but i want to use the original images of the phone. I just want to scale it. I don't wand to supply own images, because i want to keep the phone's look, and i would still have to scale them. I already tried to get the systems image resources using Setting Android CheckBox to a different image... and then back to the original images but i still could not scale the drawable. (I tried drawable.setBounds()). I'll probably also have this issue with radio buttons. Thanks for your help!

you should just be able to set the layout parameters on the checkBox:

LayoutParams lp = findViewById(R.id.chk_id).getLayoutParams();
lp.width = width;
lp.height=height;
findViewById(R.id.chk_id).setLayoutParams(lp);

By getting the layoutparams before you presever any other layout setting associated with the view

width and height are in pixels, to scale it for density use:

DisplayMetrics dm = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(dm);
        int width = (int)(150*dm.density);

you need to use the Container class for the Layout params this example is for a FrameLayout but just replace that with tyhe type of the parent container.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM