android:ImageView高度宽度与源图像拟合

标签 android image imageview image-size

我有一个页面。它从服务器加载图像并以四对的形式显示在屏幕上。有些图像的尺寸更大或更小。问题是,当图像很大时, 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/

相关文章:

android - 如何设置文件扩展名?

android - Android中的身份验证机制?

ios - 从 NSData 读取 XMP 元数据

android - JSON 中的最后一张图片未显示

android - 通用图像加载器 | SSL 握手异常 : Handshake failed

android - 如何修改 TouchImageView 双击放大缩小?

带有裁剪或 VBO 的 Android OpenGL ES draw_texture?

image - 如何使用&lt;input&gt;、<image>和canvas从本地文件系统预览一张大图

java - 将 ImageView 中的图像缩放至完整尺寸

android - 自定义 Compose Arrangement 以在 LazyRow/LazyColumn 的开头和结尾添加额外的间距