小编Jef*_*eer的帖子

如何在使用setRotation后刷新linearLayout中的match_parent?

我有几个嵌套的布局,我试图在代码中按需旋转90度.我已经把setRotation的一部分工作得很好,但不幸的是,事情并没有通过轮换来调整.这些元素的宽度设置为match_parent,旋转后它仍然匹配父宽度,而不是它应匹配的父高度.

XML

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/mainLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="link.basiclifecounter.LifeCounter"
    android:background="#CC00CC">

    <LinearLayout
        android:id="@+id/topPlayers"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="2"
        android:orientation="vertical"
        android:background="#CC0000">

        <RelativeLayout
            android:id="@+id/p3"
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1">

        **A bunch of stuff in here**

        </RelativeLayout>

        <RelativeLayout
            android:id="@+id/p2"
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1">

        **A bunch of stuff in here**

        </RelativeLayout>
    </LinearLayout>

    <LinearLayout
        android:id="@+id/bottomPlayer"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:orientation="vertical"
        android:background="#00CC00">

        <RelativeLayout
            android:id="@+id/p1"
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1">

        **A bunch of stuff in here**

        </RelativeLayout>
    </LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

旋转Java代码

view.findViewById(R.id.topPlayers).setRotation(90); //Rotate the entire top box
view.findViewById(R.id.p3).setRotation(180); //Flip one side so both …
Run Code Online (Sandbox Code Playgroud)

android rotation android-layout android-xml android-layout-weight

9
推荐指数
1
解决办法
1205
查看次数