Android 在两个布局之间旋转位置

Android 在两个布局之间旋转位置,android,layout,position,Android,Layout,Position,我对如何在两个布局之间轻松旋转位置感兴趣(RelativeLayout)。我有两个RelativeLayout,我想在单击第一个时旋转它们的位置。 我试图在控制台上创建动态位置,这样用户就可以在哪个位置上旋转他想要的东西 我已经为此创建了自己的方法,但我想知道是否有更好更简单的解决方案。在该方法中,我控制长方体内容的位置,并使用动画旋转内容 编辑: 这是看起来像主要活动的方式: <LinearLayout android:layout_width="fill_parent"

我对如何在两个布局之间轻松旋转位置感兴趣(
RelativeLayout
)。我有两个
RelativeLayout
,我想在单击第一个时旋转它们的位置。 我试图在控制台上创建动态位置,这样用户就可以在哪个位置上旋转他想要的东西

我已经为此创建了自己的方法,但我想知道是否有更好更简单的解决方案。在该方法中,我控制长方体内容的位置,并使用动画旋转内容

编辑: 这是看起来像主要活动的方式:

<LinearLayout
   android:layout_width="fill_parent"
           android:layout_height="wrap_content"
           android:orientation="vertical">
           <RelativeLayout
               android:id="@+id/first"
               android:layout_width="fill_parent"
               android:layout_height="50dp"></RelativeLayout>
           <LinearLayout
               android:layout_width="fill_parent"
               android:layout_height="wrap_content"
               android:orientation="horizontal">
               <RelativeLayout
                   android:id="@+id/seconde"
                   android:layout_width="fill_parent"
                   android:layout_height="50dp"
                   android:layout_weight="1"></RelativeLayout>
               <RelativeLayout
                   android:id="@+id/third"
                   android:layout_width="fill_parent"
                   android:layout_height="50dp"
                   android:layout_weight="1"></RelativeLayout>
               </LinearLayout>
           </LinearLayout>

您可以简化布局,如下所示:

<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <RelativeLayout
        android:id="@+id/first"
        android:layout_width="fill_parent"
        android:layout_height="50dp"
        android:background="@android:color/holo_blue_bright" >
    </RelativeLayout>

    <View
        android:id="@+id/viewSeparatorHorizontal"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_marginTop="50dp" />

    <View
        android:id="@+id/viewSeparatorVertical"
        android:layout_width="1dp"
        android:layout_height="match_parent"
        android:layout_centerHorizontal="true" />

    <RelativeLayout
        android:id="@+id/seconde"
        android:layout_width="wrap_content"
        android:layout_height="50dp"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/viewSeparatorHorizontal"
        android:layout_toLeftOf="@+id/viewSeparatorVertical"
        android:background="@android:color/holo_green_dark" >

    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/third"
        android:layout_width="wrap_content"
        android:layout_height="50dp"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/viewSeparatorHorizontal"
        android:layout_toRightOf="@+id/seconde"
        android:background="@android:color/holo_orange_dark" >
    </RelativeLayout>

</RelativeLayout>

请分享您的完整布局(xml)它很简单,两个布局一个接一个。也许我应该使用gridlayout?你的主布局是什么类型的?布局第一+第二是在相对布局或线性布局中还是?我编辑了我的问题,所以你现在可以看到如何看起来像主要的活动尼斯,如何在下面放置3个RelativeLayout?@ZoranSmederevac,我用一个简化的代码更新了我的答案,活动和布局都被更新了“在下面放置3个RelativeLayout”是什么意思?低于什么?使用xml还是编程方式?也许你可以为此发布另一个问题。我正在尝试在xml中设置第二、第三和第四个Relativelayout,在第一行下面:)请发送一个与第一个问题相同的模式
private RelativeLayout first;
private RelativeLayout third;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.test);

    first = (RelativeLayout) findViewById(R.id.first);
    third = (RelativeLayout) findViewById(R.id.third);
}

public void invert(View v){
    LayoutParams params1 = (RelativeLayout.LayoutParams)first.getLayoutParams();
    LayoutParams params3 = (RelativeLayout.LayoutParams)third.getLayoutParams();

    first.setLayoutParams(params3);
    third.setLayoutParams(params1);
}