Android: horizontal scrolling with three line layouts

I want to create an activity with a horizontal scrollview. The scrollview content will consist of three different line outputs. Each of these linearlayouts should occupy the entire screen width of the device. Therefore, when an action begins, there is only one linearlayout that occupies the entire width of the screen, and when the user swipe the screen to the right, another linearlayout will be displayed across the entire width. (see picture)

I'm not sure how to set the line widths to fit the width of the screen. Any ideas on how to solve this problem correctly?

This is what I need

+6
source share
1 answer

I think you need to use ViewFlipper instead of scrollView. use the touch event on the viewflipper to navigate and use the animation to scroll through two linear layouts.

this example will help you View a Flipper example

Edited by:

actions:

  • there is a ViewFlipper that contains layout1, layout2, layoout3
  • Currently displaying layout1.
  • fling from right to left to display the next layout. layout1 β†’ layout2

animation will be applied here in 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 childflift.

     flipper.setInAnimation(<your class>.this, R.anim.push_right_in); flipper.setOutAnimation(<your class>.this, R.anim.push_right_out); flipper.showNext(); 
    • now goes from left to right to display the previous layout. layout2 β†’ layout1

animation will be applied here in 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 childflift.

     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 smooth animation.

+9
source

Source: https://habr.com/ru/post/886223/


All Articles