草庐IT

android - android :scaleType ="fitCenter" only work with fix Layout_width and Layout_height attributes?

coder 2023-06-07 原文

我使用 Layout_width="fill_parent"和 Layout_height="wrap content"。如果图像比 ImageView 大,它将被完美地缩小。

但是,我从来没有使用它来放大较小的图像。我尝试了 ScaleType 的任意组合和“AdjustViewBounds”:它总是在 ImageView 的中间保持自己的大小。这是代码...

 <LinearLayout
        android:id="@+id/LinearLayout02"
        android:layout_height="wrap_content"
        android:background="@drawable/content_bg"
        android:orientation="vertical"
        android:padding="5dp"
        android:layout_width="fill_parent"
        android:layout_marginLeft="1px">
        <ImageView
          android:layout_height="wrap_content"
          android:src="@drawable/test"
          android:id="@+id/ImageViewTest"
          android:layout_width="fill_parent"
          android:adjustViewBounds="true"
          android:scaleType="center"></ImageView>
</LinearLayout>

最佳答案

我刚刚找到了让它工作的方法。

这适用于 2.1(AVD) 和 4.1.2(设备)

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

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="fitCenter" />

</LinearLayout>

关于android - android :scaleType ="fitCenter" only work with fix Layout_width and Layout_height attributes?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3785304/

有关android - android :scaleType ="fitCenter" only work with fix Layout_width and Layout_height attributes?的更多相关文章

随机推荐