Reputation: 7310
I want to create an activity with a horizontal scrollview. The content of the scrollview will be three different linearlayouts. Each of these linearlayouts should take up a full width of the device screen. So when the activity start there is only one linearlayout taking up the full width of the screen and when the user swipe to the right another linearlayout will show in the full width. (see picture)
I'm not sure how to set the width of the linearlayouts so they will fit the width of the screen. Any ideas on how to solve this in a good way?
Upvotes: 6
Views: 4225
Reputation: 7134
I think you have to use ViewFlipper instead of scrollView. use touch event on viewflipper for navigation and use animation for flipping of two linear Layouts.
this example will help you View Flipper example
Edited:
steps:
the animation will apply here on both views (layout1 and layout2).
for layout2 -> push_right_in.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/decelerate_interpolator">
<translate android:fromXDelta="100%" android:toXDelta="0%"
android:duration="400" />
</set>
for layout1 -> push_right_out.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/decelerate_interpolator">
<translate android:fromXDelta="0%" android:toXDelta="-100%"
android:duration="400" />
</set>
then set this animation to viewflipper's child.
flipper.setInAnimation(<your class>.this, R.anim.push_right_in);
flipper.setOutAnimation(<your class>.this, R.anim.push_right_out);
flipper.showNext();
the animation will apply here on both views (layout1 and layout2).
for layout1 -> push_left_in.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/decelerate_interpolator">
<translate android:fromXDelta="-100%" android:toXDelta="0%"
android:duration="400" />
</set>
for layout2 -> push_left_out.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/decelerate_interpolator">
<translate android:fromXDelta="0%" android:toXDelta="100%"
android:duration="400" />
</set>
then set this animation to viewflipper's child.
flipper.setInAnimation(<your class>.this, R.anim.push_left_in);
flipper.setOutAnimation(<your class>.this, R.anim.push_left_out);
flipper.showPrevious();
this will give you a smooth animation.
Upvotes: 9