Constrain drawableLeft and drawableRight's height to TextView's height

天大地大妈咪最大 提交于 2019-11-29 09:05:12

To make the loading smaller just make the images smaller.

Or use RelativeLayout and put the loading in an ImageView and scale it.

Or you can add padding between the drawables and the text using android:drawablePadding (or setCompoundDrawablePadding()):

android:drawablePadding="3dp"
Ravi

I think I found the solution, but a bit late

Drawable drawable = getResources().getDrawable(R.drawable.s_vit);
drawable.setBounds(0, 0, (int)(drawable.getIntrinsicWidth()*0.5),(int)(drawable.getIntrinsicHeight()*0.5));
ScaleDrawable sd = new ScaleDrawable(drawable, 0, scaleWidth, scaleHeight);
Button btn = findViewbyId(R.id.yourbtnID);
btn.setCompoundDrawables(sd.getDrawable(), null, null, null); 

Ravi's solution worked for me, but on some devices drawable was disappearing. Fixed this by removing the scaling.

    int bound = (int) (drawable.getIntrinsicWidth() * 0.5);
    drawable.setBounds(0, 0, bound, bound);
    b.setCompoundDrawables(drawable, null, null, null);

A Better solution will to create a XML in drawable folder and add the image to this XML, and maintain scaleType as "fitXY". Now you can make this XML as the drawableLeft.

You just need to declare two separate views imageview and textview, and set them accordingly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!