采用抽出式和图像资源时,不同的呈现?的ImageButton - Android电子 [英] Different rendering when using Drawable and Image Resource? ImageButton - Android
问题描述
我有东西在这里奇怪。我已被装载在两种不同的方式非常相同的图像
I have something strange in here. I have the very same image being loaded in two different ways:
下面是code:
if(imageAddress.startsWith("drawable")){
btn.setImageResource(this.getResources().getIdentifier(imageAddress, null, this.getPackageName()));
}else{
btn.setImageURI(Uri.parse(new File(imageAddress).toString()));
}
正如你可以在上面看到,我测试,如果图片地址以绘制开头,如果是这样的话,我加载图像作为绘制。如果没有,那么它是从SD卡的图像,然后我加载它通过其URI。
As you can see above, I test if the image address begins with "drawable", if it does, then I load the image as a drawable. If it doesn't, then it's an image from sdcard, then I load it through its URI.
下面是code为ImageButton的:
Here is the code for the ImageButton:
<ImageButton xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@drawable/roundcorners"
android:scaleType="centerInside"
android:cropToPadding="false"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingBottom="10dip"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:layout_weight=".95">
</ImageButton>
和下面是这样的结果:
上图显示的ImageButton加载可绘制(imageAddress =绘制/ eu_quero)
Above image shows ImageButton when loaded AS DRAWABLE (imageAddress = "drawable/eu_quero")
上图显示的ImageButton加载通过图像的URI(imageAddress =/mnt/sdcard/myapp/images/eu_quero.png)
Above image shows ImageButton when loaded THROUGH IMAGE URI (imageAddress = "/mnt/sdcard/myapp/images/eu_quero.png")
我需要的是图像是相同的大小,不管我加载它作为绘制或通过ImageURI。
谁能帮我请??
重要提示:图像是完全一样的!相同尺寸!!
推荐答案
你能尝试实施的android:margin_left,而不是填充:左
Can you try implementing android:margin_left instead of padding:left ?
这篇关于采用抽出式和图像资源时,不同的呈现?的ImageButton - Android电子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!