我有一个页面。它从服务器加载图像并以四对的形式显示在屏幕上。有些图像的尺寸更大或更小。问题是,当图像很大时, ImageView 会自行拉伸(stretch)到图像的实际大小。我希望无论图像大小如何,它都必须适合 ImageView ,而不会干扰其他 3 个图像。它的 xml 是“
<LinearLayout android:id="@+id/videolist"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@+id/trendingnowmanual"
android:layout_above="@+id/navigatevideo"
android:gravity="center_vertical|center_horizontal"
android:background="#ffffff"
android:layout_marginLeft="20dip"
android:layout_marginRight="20dip"
android:layout_marginTop="5dip"
android:layout_marginBottom="5dip" >
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical|center_horizontal"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:layout_marginTop="10dip"
android:layout_marginBottom="5dip"
android:layout_weight="100">
<ImageView android:id="@+id/one"
android:src="@drawable/add1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="5dip"
android:layout_weight="50"
android:adjustViewBounds="true"
>
</ImageView>
<ImageView android:id="@+id/two"
android:src="@drawable/add2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="5dip"
android:layout_weight="50"
android:adjustViewBounds="true"
>
</ImageView>
</LinearLayout>
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical|center_horizontal"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:layout_marginTop="5dip"
android:layout_marginBottom="10dip"
android:layout_weight="100" >
<ImageView android:id="@+id/three"
android:src="@drawable/add3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="5dip"
android:layout_weight="50"
android:adjustViewBounds="true"
>
</ImageView>
<ImageView android:id="@+id/four"
android:src="@drawable/add4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="5dip"
android:layout_weight="50"
android:adjustViewBounds="true"
>
</ImageView>
</LinearLayout>
</LinearLayout>
有什么想法吗?
最佳答案
在 ImageView 中使用scaleType="fitXY"
关于android:ImageView高度宽度与源图像拟合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6855289/