RadioButton的相关

要实如今Android RadioButton上显示图片和文字,使用XML文件就能够,但有时却必需要使用java code的方式动态来实现,这样有些复杂了,这须要继承RadioButton并覆盖其中的onDraw方法。
html

在代码中的image是Bitmap对象。java

@Override 
protected void onDraw(Canvas canvas) {
	super.onDraw(canvas);
    if (image != null) { 
        Paint pt = new Paint(); 
        pt.setARGB(255,66,66,66); 
        
        // 消除锯齿 
        pt.setAntiAlias(true); 
        
        // 居中显示 图片 
        int imageX=(int)(this.getWidth()-image.getWidth())/2; 
    
        canvas.drawBitmap(image,imageX,5,pt); 
        pt.setARGB(255,255,255,255); 
        // 居中显示字符串 
        int strX=(int)(this.getWidth()-name.getBytes().length*5.5)/2; 
        canvas.drawText(name,strX,(image.getHeight()+15),pt);
    }
}

上文转自:http://www.android-study.com/jiemiansheji/484.htmlandroid

下面这篇文章是关于改变RadioButton文字和图片相对位置的:canvas

http://www.oschina.net/code/snippet_246750_16190 ide

ViewPager + RadioButton实现仿QQ效果:
this

http://my.oschina.net/qibin/blog/316650 spa

自定义RadioButton实现文字上下左右方向的图片大小设置:.net

http://www.2cto.com/kf/201503/384738.html code

相关文章
相关标签/搜索