0

试试自己 - 用 anyPngYouWant.png 放置一个 ImageView 布局,然后用它制作一个 bitmap.xml

<bitmap xmlns:android="http://schemas.android.com/apk/res/android" 
    android:src="@drawable/anyPngYouWant"
 />

并放入相同的布局..

为什么它们的大小不同?我尝试了许多不同的图像,但在 bitmal.xml 中 wrap_content 的大小仍然与源 png 不同。我只希望它们相同

布局 :

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"

    tools:context=".MainActivity" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:src="@drawable/anyPngYouWant" />

    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/imageView1"
        android:src="@drawable/bitmap" />

</RelativeLayout>
4

1 回答 1

0

检查此方法,它获取图像文件的 Bitmap 对象,然后设置为imageView

File ifile = new  File(“PATH/anyPngYouWant.png”);
if(ifile.exists()){

    Bitmap bmp = BitmapFactory.decodeFile(ifile.getAbsolutePath());

    ImageView iv = (ImageView) findViewById(R.id.imageView1);
    iv.setImageBitmap(bmp);

}
于 2013-08-08T10:58:56.250 回答