Different rendering when using Drawable and Image Resource? ImageButton - Android

ぐ巨炮叔叔 提交于 2019-12-11 10:38:07

问题


I have something strange in here. I have the very same image being loaded in two different ways:

Here is the code:

     if(imageAddress.startsWith("drawable")){
         btn.setImageResource(this.getResources().getIdentifier(imageAddress, null, this.getPackageName()));
     }else{
         btn.setImageURI(Uri.parse(new File(imageAddress).toString()));
     }

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.

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>

And below is the RESULT of this:

Above image shows ImageButton when loaded AS DRAWABLE (imageAddress = "drawable/eu_quero")

Above image shows ImageButton when loaded THROUGH IMAGE URI (imageAddress = "/mnt/sdcard/myapp/images/eu_quero.png")

What I need is the images to be the same size, no matter if I load it as drawable or through ImageURI.

Can anyone help me please??

IMPORTANT: IMAGES ARE EXACTLY THE SAME!!! SAME SIZE!!


回答1:


Can you try implementing android:margin_left instead of padding:left ?



来源:https://stackoverflow.com/questions/9064808/different-rendering-when-using-drawable-and-image-resource-imagebutton-androi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!