how to swipe only a portion of the layout

冷暖自知 提交于 2020-01-01 19:31:15

问题


I'm using ViewPagerIndicator Library by Jake Wharton and I'm trying to have the same browsing as Tinder and a lot of recent android apps(Talking about the starting screen)...I mean only the top part of the layout is swipeable, and a smaller part at the bottom shows Fb/Twitter/G+ login buttons.

here is a screenshot of what I wish to have : http://i.imgur.com/QK91rBW.png

I already read this Question, but I think it does not answer my need.

Can you guys help me please ?


回答1:


Well since you'll be using a ViewPager you don't have to think about the region which is swipeable since the height / width of the ViewPager determines this.

Layout example:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <!-- Static content -->
    <LinearLayout
        android:id="@+id/ll_bottom"
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:layout_alignParentBottom="true"
        android:background="@color/holo_blue_light"
        android:orientation="vertical" />

    <!-- ViewPager Indicator -->
    <com.viewpagerindicator.LinePageIndicator
        android:id="@+id/view_pager_indicator"
        android:layout_width="fill_parent"
        android:layout_height="20dp"
        android:layout_above="@id/ll_bottom"
        android:background="@color/holo_orange_light"
        app:lineWidth="10dp"
        app:selectedColor="#fff"
        app:strokeWidth="10dp"
        app:unselectedColor="#888888" />

    <!-- ViewPager containing fragments with different views -->
    <android.support.v4.view.ViewPager
        android:id="@+id/view_pager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@id/view_pager_indicator"
        android:layout_alignParentTop="true"
        android:background="@color/holo_red_light" />

</RelativeLayout>

Result:

Explanation: In the blue region you place your static content which doesn't change like the Facebook-Button in your example. The orange region is used by the ViewPagerIndicator and finally the red region is the one of the ViewPager. As previously said only this area is swipeable.



来源:https://stackoverflow.com/questions/24622942/how-to-swipe-only-a-portion-of-the-layout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!