![]() ![]() TickRememberPasswd.The average professional spends 28% of the work day reading and answering email, according to a McKinsey analysis. If (drawableTick != null & drawableUntick != null), //else state_checked false Then simply remove in your checkbox xml, and do drawable scaling programmatically in java (decrease the 150 big size to your desired dp): CheckBox tickRememberPasswd = findViewById(R.id.remember_tick) ĭrawable drawableTick = ContextCompat.getDrawable(this, R.drawable.tick_img) ĭrawable drawableUntick = ContextCompat.getDrawable(this, R.drawable.untick_img) If you put a WonCheckBox in your view and apply setHeight(), the check-box image will be of the right size. call the checkbox's internal setHeight() SetPadding((int)(scale * origPadLeft), 0, 0, 0) This is unnecessary on Android 4.2.2, but very important on previous versions. Make sure the text is not overlapping with the image. ** set checkbox height in pixels directly */įloat scale = (float)height / origHeight I tried origImg.mutate(), but that fails on Android 2.1 (NullPointerException)ĬheckImg = new ScalingDrawable(origImg, 1) OrigHeight = height = origImg.getIntrinsicHeight() get the original drawable and get its heightĭrawable origImg = WonActivity.W.getDefaultCheckBoxDrawable() Super(WonActivity.W.getApplicationContext()) ** original height of the check-box image */ Public class WonCheckBox extends CheckBox Return (int)(super.getIntrinsicHeight() * scaleY) įinally, I defined a checkbox class. Return (int)(super.getIntrinsicWidth() * int getIntrinsicHeight() The following is what I wrote this int getIntrinsicWidth() ** set the scale - proportional scaling */ Void setScale(float scaleX, float scaleY) ScalingDrawable(Drawable d, float scaleX, float scaleY) Public class ScalingDrawable extends LayerDrawable ** The drawable that scales the contained drawable */ Please notice that it is completely different from the standard ScaleDrawable. Second, I created a class to "scale a drawable". Return getResources().getDrawable(resID) GetApplicationContext().getTheme().resolveAttribute(android.R.attr.listChoiceIndicatorMultiple, value, true) starting with Honeycomb, retrieve the theme-based indicator as CheckBox button drawable ResID = Resources.getSystem().getIdentifier("btn_check", "drawable", "android") pre-Honeycomb has a different way of setting the CheckBox button drawable This was taken directly from Stack Overflow - thank you guys! /** get the default drawable for the check box */ I don't pretend that the solution is perfect if anyone knows a way to shorten some of the steps, I'll be happy to find out how.įirst, I put the following in the main activity class of the project (WonActivity). In other words, the system image is being scaled. I found a way to do it without creating your own images. You need two PNGs cb_checked.png and cb_unchechecked.png add them to drawable folder So, this answer is for checkbox with text like below where you want to resize the checkbox drawable and text separately. I could not find the relevant answer for my requirement which I figured it out. You can change its width and height or viewportHeight and viewportWidth Step 3: Set that drawable into check box Step 2: Create XML selector for check_box ( Note if you are workiong with Android Studio, you can also add these Vector Drawable from there, Right click on your drawable folder then New/Vector Asset, then select these drawable from there) ![]() Step 1: Copy these three Vector Drawable to your drawable folder png Images(its also creating problem with different screen size)īut we have another solution for that, that is Vector Drawable Here as per my UI requirement i can't not increase TextSize so other option i tried is scaleX and scaleY (Strach the check box) and custom xml selector with. Well i have found many answer, But they work fine without text when we require text also with checkbox like in my UI ![]()
0 Comments
Leave a Reply. |