【问题标题】:Different rendering when using Drawable and Image Resource? ImageButton - Android使用 Drawable 和 Image Resource 时的不同渲染?图像按钮 - 安卓
【发布时间】:2012-01-30 13:44:01
【问题描述】:

我这里有一些奇怪的东西。我以两种不同的方式加载了相同的图像:

代码如下:

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

正如你在上面看到的,我测试图像地址是否以“drawable”开头,如果是,那么我将图像加载为drawable。如果没有,那么它是来自 sdcard 的图像,然后我通过它的 URI 加载它。

这是 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>

下面是这个结果:

上图显示加载为 DRAWABLE 时的 ImageButton (imageAddress = "drawable/eu_quero")

上图显示通过 IMAGE URI (imageAddress = "/mnt/sdcard/myapp/images/eu_quero.png") 加载时的 ImageButton

我需要的是相同大小的图像,无论我将其加载为可绘制的还是通过 ImageURI 加载。

谁能帮帮我吗?

重要提示:图片完全相同!!!大小一样!!

【问题讨论】:

标签: android imagebutton


【解决方案1】:

你可以尝试实现 android:margin_left 而不是 padding:left 吗?

【讨论】:

    猜你喜欢
    • 2014-07-26
    • 2011-01-18
    • 1970-01-01
    • 1970-01-01
    • 2017-09-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-01
    相关资源
    最近更新 更多