<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);
}
}