繁体   English   中英

旋转ImageView而不会失去高度

[英]Rotate ImageView without losing Height

我在Android Studio上使用ImageView遇到问题。

基本上,当我旋转视图(90°)时,尺寸会互换(“高度”现在是“宽度”,而“宽度”现在是“高度”),导致ImageView超出范围。 这已经是2天的挣扎,我真的需要一个答案。

正常:

旋转:

注意:我使用setImageResource以编程方式在ImageView设置资源

谢谢!

您可以按以下方式尝试库链接

在项目的build.gradle中包括此库依赖项

compile 'rongi.rotate-layout:rotate-layout:3.0.0'

并且出于旋转目的,您需要使用“ RotateLayout”包装视图

<com.github.rongi.rotate_layout.layout.RotateLayout
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:angle="90"> <!-- Specify rotate angle here -->

    <YourLayoutHere
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
    </YourLayoutHere>
</com.github.rongi.rotate_layout.layout.RotateLayout>

如果要以编程方式旋转它,则

int newAngle = rotateLayout.getAngle() + 90;
rotateLayout.setAngle(newAngle);

根据您提供的信息(在这种情况下,您应该提供布局示例),我认为您需要的是在图像视图中更改scaleType

有关不同选项的直观指南,请参阅本文: Android ImageView ScaleType:直观指南

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM