【问题标题】:How to rotate ImageView and have its size adjust automatically?如何旋转 ImageView 并自动调整其大小?
【发布时间】:2016-09-09 01:27:39
【问题描述】:

图像 1 没有旋转,当我旋转 ImageView 时,我想要图像 3,但正在显示类似于图像 2 的东西。如何让ImageView 自动更改其尺寸?
我的猜测是,旋转后,ImageView 的宽度和高度被保留了,我不希望这样
附言我不想改变布局的方向
这是图片(矩形是电话,人是imageview)

这是我的 xml

    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent" android:layout_height="fill_parent"
        android:id="@+id/page">

    <ImageView
        android:scaleType="centerInside" 
        android:layout_height="wrap_content" 
        android:layout_width="wrap_content"
        android:id="@+id/character" 
        android:rotation="90"
     />
    </FrameLayout>
<!-- I tried all scaleTypes, and set height/width to fill_parent, wrap_content,and match_parent nothing worked-->

感谢任何帮助。谢谢!

【问题讨论】:

  • 你找到解决办法了吗?

标签: android xml


【解决方案1】:

删除 adjustViewBounds 并使用 scaleType fitCenter。它应该工作。试试这个:

<ImageView
    android:scaleType="fitCenter" 
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content"
    android:id="@+id/character"
    android:rotation="90"
 />

【讨论】:

  • 不走运。谢谢你!
【解决方案2】:

试试这个:

<ImageView
    android:scaleType="fitCenter" 
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content"
    android:id="@+id/character"
    android:adjustViewBounds="true" 
    android:rotation="90"
 />

编辑:

 android:adjustViewBounds="true" 

将设置scaleType="fitCenter",所以我认为你应该尝试scaleTypeadjustBounds,不能同时使用。

 <ImageView
    android:scaleType="fitCenter" 
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content"
    android:id="@+id/character"
    android:rotation="90"
 />

【讨论】:

  • 没有运气对不起。在没有任何效果之前,我尝试设置所有可能的“scaleTypes”。 “FitXY”会扭曲图像,因此也不起作用
  • android:adjustViewBounds="true" 会设置set scaleType="fitCenter" ,你的一切尝试都是徒劳的!
  • 是的,我尝试不使用“adjustViewBounds”,但这也不起作用。也尝试过“centerInside”
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-02-21
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多