I have a tablelayout in Android like this:
1) Row == IMAGEVIEW | TEXTVIEW
2) Row == IMAGEVIEW | SPINNER
Now what I need to do is switch the TEXTVIEW/SPINNER. The one from row 2 goes to row 1 and the one from 1 goes to 2.
Would be awesome to have a little animation also. I've seen Viewswitcher and Viewflipper but This doesn't seem to be what I am looking for. Anyone got a good idea how to get this to work?
My layout (a piece of it) looks like this:
<TableRow>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/left_layout_controlls"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:stretchColumns="*"
android:id="@+id/top_controlls"
android:layout_height="wrap_content">
<TableRow>
<ImageView
android:id="@+id/fromCountry_img"
android:src="@drawable/tc_rt_from"
android:layout_width="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_height="fill_parent"
/>
<TextView
android:id="@+id/fromCountry"
android:layout_marginTop="2px"
android:layout_marginLeft="2px"
android:background="@drawable/round_edges_main_controll"
android:layout_marginRight="2px"
android:layout_height="38px"
android:layout_width="160dip"/>
</TableRow>
</TableLayout>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:stretchColumns="*"
android:layout_below="@id/top_controlls"
android:layout_height="wrap_content">
<TableRow>
<ImageView
android:src="@drawable/tc_rt_to"
android:layout_width="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_height="fill_parent"
android:layout_below="@id/fromCountry_img"
/>
<Spinner
android:id="@+id/toCountry"
android:layout_height="wrap_content"
android:layout_marginTop="2px"
android:layout_marginBottom="2px"
android:layout_marginRight="2px"
android:layout_width="160dip"
android:layout_weight="1"
android:drawSelectorOnTop="true"/>
</TableRow>
</TableLayout>
Update:
I've tried to switch the controlls like this, and the animation works, but when the animation ends, the controlls will jump back into their old position.
Any idea why?
LinearLayout layout1 = ((LinearLayout) DataHolder.activityHolder.findViewById(R.id.top_controll));
LinearLayout layout2 = ((LinearLayout) DataHolder.activityHolder.findViewById(R.id.bottom_controll));
DataHolder.activityHolder.findViewById(R.id.toCountry));
TranslateAnimation a = new TranslateAnimation(
Animation.ABSOLUTE,0,Animation.ABSOLUTE,0,
Animation.ABSOLUTE,0,Animation.ABSOLUTE, 40);
a.setDuration(1200);
TranslateAnimation b = new TranslateAnimation(
Animation.ABSOLUTE,0,Animation.ABSOLUTE,0,
Animation.ABSOLUTE,0,Animation.ABSOLUTE, -40);
b.setDuration(1200);
layout1.startAnimation(a);
layout2.startAnimation(b);