2014-11-06 209 views

回答

1

在您的ImageView设置android:adjustViewBounds="true"通过XML

<ImageView 
    android:id="@+id/imageView1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:src="@drawable/your_image"" /> 

拥有财产性wrap_content

。你可以阅读更多关于它here

因此,您的ImageView的XML将是这样的:

<ImageView 
    android:id="@+id/iv_image" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:adjustViewBounds="true" 
    android:src="@drawable/image"" /> 
0

的ImageView通过Java代码

ImageView imageView = new ImageView(this); 
imageView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT)); 
imageView.setImageResource(R.drawable.your_image);