展会信息港展会大全

如何使用viewpager?制作滑动切换效果
来源:互联网   发布日期:2016-01-14 11:35:12   浏览:1833次  

导读:LinearLayout android:id=@+id/tab android:layout_below=@id/header android:layout_width=match_parent android:layout_height=37dp RelativeLayout android:id=@+id/goods_list_button android:background=#3f4147 android:layout_weight=1 android:layou...

<LinearLayout

android:id="@+id/tab"

android:layout_below="@id/header"

android:layout_width="match_parent"

android:layout_height="37dp">

<RelativeLayout

android:id="@+id/goods_list_button"

android:background="#3f4147"

android:layout_weight="1"

android:layout_width="0dp"

android:layout_height="match_parent">

<TextView

android:layout_centerInParent="true"

android:text="商品列表"

android:textSize="15sp"

android:textColor="#7e7e7e"

android:layout_width="wrap_content"

android:layout_height="wrap_content" />

<FrameLayout

android:id="@+id/goods_list_footer"

android:visibility="gone"

android:layout_alignParentBottom="true"

android:background="#3993cf"

android:layout_width="match_parent"

android:layout_height="5dp"></FrameLayout>

</RelativeLayout>

<FrameLayout

android:layout_gravity="center"

android:layout_width="1dp"

android:background="#55575d"

android:layout_height="match_parent"></FrameLayout>

<RelativeLayout

android:id="@+id/shop_introduce_button"

android:background="#3f4147"

android:layout_weight="1"

android:layout_width="0dp"

android:layout_height="match_parent">

<TextView

android:layout_centerInParent="true"

android:text="店铺介绍"

android:textSize="15sp"

android:textColor="#7e7e7e"

android:layout_width="wrap_content"

android:layout_height="wrap_content" />

<FrameLayout

android:id="@+id/shop_introduce_footer"

android:visibility="gone"

android:layout_alignParentBottom="true"

android:background="#3993cf"

android:layout_width="match_parent"

android:layout_height="5dp"></FrameLayout>

</RelativeLayout>

</LinearLayout>

<android.support.v4.view.ViewPager

xmlns:android="http://schemas.android.com/apk/res/android"

android:id="@+id/pager"

android:layout_below="@id/tab"

android:layout_width="match_parent"

android:layout_height="match_parent" />

private void setUpViewPager() {

viewPager.setAdapter(new FragmentPagerAdapter(getChildFragmentManager()) {

@Override

public Fragment getItem(int position) {

if (0 == position) {

return ShopListFragment.newInstance();

}

else {

return ShopMoreInfoFragment.newInstance();

}

}

@Override

public int getCount() {

return 2;

}

});

viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

@Override

public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

}

@Override

public void onPageSelected(int position) {

if (0 == position) {

setListTabSelected();

}

else {

setIntroduceTabSelected();

}

}

@Override

public void onPageScrollStateChanged(int state) {

}

});

}

private void setListTabSelected() {

UIHelper.setLayoutSelected(shoppingList, true);

UIHelper.setLayoutSelected(shoppingIntroduce, false);

shoppingListFooter.setVisibility(View.VISIBLE);

shoppingIntroduceFooter.setVisibility(View.GONE);

}

private void setIntroduceTabSelected() {

UIHelper.setLayoutSelected(shoppingList, false);

UIHelper.setLayoutSelected(shoppingIntroduce, true);

shoppingListFooter.setVisibility(View.GONE);

shoppingIntroduceFooter.setVisibility(View.VISIBLE);

}

public static void setLayoutSelected(ViewGroup viewGroup, boolean selected) {

viewGroup.setSelected(selected);

for (int i = 0; i < viewGroup.getChildCount(); i++) {

View view = viewGroup.getChildAt(i);

view.setSelected(selected);

}

}

赞助本站

人工智能实验室

相关热词: android开发 android教程

AiLab云推荐
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港