java单选框能调整大小吗_改变单选按钮的图片大小-单选框

/*** 改变单选按钮左上右下部分的图片大小

*@authorAdministrator*/

public class MyRadioButton extendsRadioButton {private int mDrawableSize;//xml文件中设置的大小

publicMyRadioButton(Context context) {this(context, null, 0);

}publicMyRadioButton(Context context, AttributeSet attrs) {this(context, attrs, 0);

}public MyRadioButton(Context context, AttributeSet attrs, intdefStyle) {super(context, attrs, defStyle);

Drawable drawableLeft= null, drawableTop = null, drawableRight = null, drawableBottom = null;

TypedArray a=context.obtainStyledAttributes(attrs, R.styleable.MyRadioButton);//解析自定义的属性,为图片设置尺寸大小

int n =a.getIndexCount();for (int i = 0; i < n; i++) {int attr =a.getIndex(i);switch(attr) {caseR.styleable.MyRadioButton_drawableSize:

mDrawableSize= a.getDimensionPixelSize(R.styleable.MyRadioButton_drawableSize, 50);break;caseR.styleable.MyRadioButton_drawableTop:

drawableTop=a.getDrawable(attr);break;caseR.styleable.MyRadioButton_drawableBottom:

drawableRight=a.getDrawable(attr);break;caseR.styleable.MyRadioButton_drawableRight:

drawableBottom=a.getDrawable(attr);break;caseR.styleable.MyRadioButton_drawableLeft:

drawableLeft=a.getDrawable(attr);break;

}

}

a.recycle();//回收

setCompoundDrawablesWithIntrinsicBounds(drawableLeft, drawableTop, drawableRight, drawableBottom);

}/*** 为图片设置边界,即要显示的大小*/

public voidsetCompoundDrawablesWithIntrinsicBounds(Drawable left,

Drawable top, Drawable right, Drawable bottom) {if (left != null) {

left.setBounds(0, 0, mDrawableSize, mDrawableSize);//为图片设置边界

}if (right != null) {

right.setBounds(0, 0, mDrawableSize, mDrawableSize);

}if (top != null) {

top.setBounds(0, 0, mDrawableSize, mDrawableSize);

}if (bottom != null) {

bottom.setBounds(0, 0, mDrawableSize, mDrawableSize);

}//设置合成的图片文字

setCompoundDrawables(left, top, right, bottom);

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值