0

I'm interested how to easy rotate position between two layouts (RelativeLayout). I have two RelativeLayout and I want to rotate their position when I click on first. I'm trying to create dynamic position on console, so user can rotate what he want to be on which position.

enter image description here

I have created my own method for this, but I want to know is there any better and simpler solution. In that method I control where is which content of box and I rotate content with animation.

Edit: This is how to look like main_activity:

<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>
madhan kumar
  • 1,560
  • 2
  • 26
  • 36

1 Answers1

0

You could simplify your layout as this:

<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>

And use this code to "rotate" components:

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);
}
LaurentY
  • 7,495
  • 3
  • 37
  • 55
  • nice, how to put 3 RelativeLayout below? – ZoranSmederevac Apr 16 '15 at 15:11
  • @ZoranSmederevac, I update my answer with a simplified code, activity and layout are updated – LaurentY Apr 16 '15 at 15:25
  • What do you mean by "put 3 RelativeLayout below" ? below what ? when in xml or programmatically ? Maybe you could post another question for this. – LaurentY Apr 16 '15 at 15:27
  • i'm trying to set in xml seconde, third and fourth Relativelayout in same row below first :) – ZoranSmederevac Apr 16 '15 at 15:30
  • Please send a schema as in your first question – LaurentY Apr 16 '15 at 15:32
  • [Picture](http://www.dodaj.rs/f/39/Ao/2HhYiIkH/newstack.png) You can see what i mean – ZoranSmederevac Apr 16 '15 at 15:37
  • To adapt to all screen size, you could set width size to 3 cells programatically. Align first to left, second to middle, thrid to right. get root size as http://stackoverflow.com/questions/17541993/android-get-the-size-of-the-body-layout-dynamically#17542132 set (root size / 3) to each cells width – LaurentY Apr 16 '15 at 15:47