【问题标题】:Stretch to fill ImageView with rotated image拉伸以使用旋转图像填充 ImageView
【发布时间】:2018-02-05 20:38:50
【问题描述】:

我希望它用我的旋转图像填充 ImageView。 这是我的 ImageView 代码:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<ImageView
    android:id="@+id/imgResult"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:rotation="90"
    android:scaleType="fitXY"
    android:src="@drawable/img_ex" />

<LinearLayout
    android:id="@+id/linearLayout"
    style="?android:attr/buttonBarStyle"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.0"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintStart_toStartOf="parent">

    <Button
        android:id="@+id/btCancelar"
        style="?android:attr/buttonBarButtonStyle"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="Cancelar"
        app:layout_constraintBottom_toBottomOf="parent"
        />

    <View
        android:layout_width="1dp"
        android:layout_height="match_parent"
        android:background="#fff" />

    <Button
        android:id="@+id/btSalvar"
        style="?android:attr/buttonBarButtonStyle"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="Salvar"
        app:layout_constraintBottom_toBottomOf="parent"
        />
</LinearLayout>

</LinearLayout>

在图片中,您可以在蓝图中看到 imageview 的大小。

我不介意拉伸图片,我​​只想填充 ImageView 组件

PS:我已经尝试过这个解决方案Scaling ImageView to device width

【问题讨论】:

  • @AkashPal 不起作用。我仍然得到图像周围的白色边框
  • @AkashPal 也不工作
  • 如果去掉权重,让 ImageView 匹配父级宽高会怎样?
  • fitXY 不需要adjustViewBounds
  • 能否请您发布您的图片,以便我们检查

标签: android imageview


【解决方案1】:

我的解决方案是在显示之前在我的活动中旋转位图。然后就成功了

fun rotateBitmap(source: Bitmap, angle: Float): Bitmap {
    val matrix = Matrix()
    matrix.postRotate(angle)
    return Bitmap.createBitmap(source, 0, 0, source.width, source.height, matrix, true)
}

【讨论】:

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