簡體   English   中英

如何在android中旋轉視圖並調整其相對於父視圖的高度

[英]How to rotate a view in android and also adjust its height in respect to parent view

我正在嘗試將視圖旋轉到從 0 到 360 的任何所需位置,這是一個浮動視圖,它也應該轉到屏幕邊緣,所以我不想創建一個方形框來旋轉視圖我希望它只是為了查看旋轉視圖所需的位置。

我可以旋轉視圖,但問題是它被父級裁剪,只有初始視圖可見,其余部分正在裁剪。 如下圖所示:

在此處輸入圖像描述

這是我正在使用的代碼:

public void rotateView(int angle) {
        floatingView.setRotation(angle);
    }

一種解決方案是我正在考慮在旋轉視圖以設置新的高度和寬度時使用視圖的對角線值,但不確定如何使用它來僅考慮旋轉部分的寬度或高度。

你可以檢查這個庫,它讓你很容易: https://github.com/rongi/rotate-layout\因為它有你正在尋找的功能,邊界框與里面的視圖一起旋轉。

例子

用法

implementation 'rongi.rotate-layout:rotate-layout:3.0.0'
<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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM