【问题标题】:android imageview wrap_contentandroid imageview wrap_content
【发布时间】:2014-11-17 16:39:36
【问题描述】:

大家好,感谢您的帮助。

我在 Android Studio 中有一个项目。

我在垂直 LinearLayout 中使用 ImageView。

这是我的参数;

<ImageView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:id="@+id/imageView2"
    android:src="@drawable/myimg"
/>

您可以在下方看到我的图像(红色块)和图像视图边框(蓝线) 宽度没有问题,它是我布局的 %100,但我希望我的图像适合该区域,同时保持纵横比。正如您在图像中看到的那样,有空格,ImageView 的高度比我的图像大,我怎样才能在 ImageView 中放置图像?

我想要这个,因为我希望该图像适合宽度,即使手机是纵向或横向的。

【问题讨论】:

  • 代替android:src,使用android:background,然后check。可以根据需要得到需要的效果。

标签: android imageview width fill-parent


【解决方案1】:

我找到了解决方案 android:adjustViewBounds="true"

【讨论】:

  • 你救了我大哥
【解决方案2】:

imageview 的大小是正确的。您必须相应地缩放图像。ImageView 具有缩放属性。试试这个android:scaleType="fitXY" 并告诉我。

【讨论】:

  • 当我使用“fitXY”时,我的图像的纵横比正在改变,我的图像看起来很糟糕。
【解决方案3】:

你的代码是写的,但我不知道父布局,你的图像背景是白色的,红色部分在这个背景的中间。

这是与父布局相关的代码

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MyActivity">



<ImageView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:id="@+id/imageView"
    android:src="@drawable/red"
     />

【讨论】:

    【解决方案4】:

    对于ImageViewandroid:scaleType="fitXY" 将丢失纵横比。最好使用android:scaleType="fitCenter" 并为imageView transparent 设置背景。

    如果您不想保持纵横比,那么setbackground()fitxy 将满足您的要求

    【讨论】:

      【解决方案5】:

      在imageview中,有一个中心裁剪选项-

      android:scaleType="centerCrop"
      

      它将做的是从中心裁剪图像。输出将像 -

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-04-22
        • 1970-01-01
        • 1970-01-01
        • 2016-11-06
        • 2013-11-09
        相关资源
        最近更新 更多