【问题标题】:How to scale Android ImageView width according to layout_alignTop and layout_alignBottom如何根据 layout_alignTop 和 layout_alignBottom 缩放 Android ImageView 宽度
【发布时间】:2013-12-02 22:32:48
【问题描述】:

我想要一个简单的播放器视图,其中包含图像、名称和状态。图片将通过 Google+ 加载。

我遇到的问题是,对于大图像,我的 ImageView 变得太宽,并且将我的文本推到视线之外。

下面是一个例子来展示它的样子: https://dl.dropboxusercontent.com/u/11037539/unwanted_padding.png

布局:

<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:id="@+id/playerPane"
    android:background="@color/player2">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@+id/playerName"
        android:layout_alignBottom="@+id/playerStatus"
        android:id="@+id/playerImage"
        android:src="@drawable/ic_contact_picture"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@+id/playerImage"
        android:id="@+id/playerName"
        android:text="Player"
        android:textColor="@android:color/black"
        android:singleLine="true"
        android:textStyle="bold"
        android:paddingTop="@dimen/player_padding"
        android:paddingBottom="@dimen/player_padding"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/playerName"
        android:layout_alignLeft="@+id/playerName"
        android:id="@+id/playerStatus"
        android:text="status"
        android:singleLine="true"
        android:paddingBottom="@dimen/player_padding" />
</RelativeLayout>

我已经尝试了所有 ImageView.scaleTypes,但到目前为止没有任何效果..

非常感谢您的帮助!

【问题讨论】:

  • 图像视图会发生这种情况。我通常将宽度设置为固定尺寸。

标签: android imageview scale measure


【解决方案1】:

你只需要定义你的宽度。它应该修复它。所以改变这一行

类似于:

   <ImageView
        android:layout_width="75dp" //OR WHATEVER LOOKS BEST

【讨论】:

  • 非常感谢,我这样做并删除了“layout_alignTop and Bottom”,效果很好:)。
  • @DanBad。哦,是的,我没有注意到这一点。这不是一个好习惯。但很高兴能提供帮助
【解决方案2】:

ScaleType 仅在 imageview 的大小小于图像时才真正有用。如前所述,设置大小,然后您可以使用 scaleType 来修复图像在现在更小的区域内应如何缩放。

【讨论】:

    猜你喜欢
    • 2017-07-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多