2014-11-06 206 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);