[英]android get the drawable that has sett as drawabletop of textview
[英]DrawableTop not showing drawable
我正在尝试使用drawableTop在按钮中的文本上方显示图片。
我的图片来自sdcard,而不是可绘制的。
此外,按钮的大小可能会根据显示的按钮数量而变化。 更多的按钮,较小的按钮,然后较小的图像。
这是我创建按钮的方式:
btn = (Button) LayoutInflater.from(
getBaseContext()).inflate(
R.layout.buttonstyle, l1, false);
这是XML文件的按钮样式:
<?xml version="1.0" encoding="UTF-8"?>
<Button xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@drawable/roundcorners"
android:id="@+id/buttonTest"
android:scaleType="centerInside"
android:cropToPadding="false"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingBottom="10dip"
android:layout_height="fill_parent"
android:layout_width="wrap_content"
android:text="Test text"
android:textSize="40dip"
android:textStyle="bold"
android:textColor="#000000">
</Button>
这是我创建drawableTop的方法:
Drawable drawableTop = Drawable.createFromPath(endImagemVoltar);
btn.setCompoundDrawables(null, drawableTop, null, null);
文本显示在按钮中,但未显示图像。
错误在哪里?
任何帮助表示赞赏!
我想缺少的是您的drawable已经调用了setBounds(Rect),还尝试将图片加载到位图中,然后将其放入drawable中:
Bitmap bitmapImage = BitmapFactory.decodeFile(endImagemVoltar);
Drawable bgrImage = new BitmapDrawable(bitmapImage);
要使用SetBounds:
public void setBounds (int left, int top, int right, int bottom)
例如50x50尺寸,请使用:
drawable.setBounds(0,0,50,50);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.