[英]Align icon just left to the text in Button android
我有一个按钮,我想在按钮文本的左侧放置一个图像。
Button b = new Button(this);
l.addView(b);
LinearLayout.LayoutParams pa = new LinearLayout.LayoutParams(-1, -2);
b.setLayoutParams(pa);
b.setText("Prueba");
Drawable img = getResources().getDrawable(R.drawable.ic_launcher);
b.setCompoundDrawablesWithIntrinsicBounds(img, null, null, null);
但按钮宽度匹配父按钮和图像左对齐按钮和文本是对齐按钮的中心。
编辑:
我明白了
..但我希望图像只对齐左侧文本而不是右侧按钮的右边缘
我希望看到这样的:
http://img543.imageshack.us/img543/6534/img20130404111534.jpg
任何想法?
用这个
LinearLayout.LayoutParams pa = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
如果你想设置重力使用这个
LinearLayout.LayoutParams pa = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
pa.gravity=Gravity.RIGHT;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.