我有一个与viewpager一起使用的页脚。当我向左或向右滑动时,页脚也会向左或向右滑动。我希望在viewpager上的每个页面上修复页脚。即使我刷页面,任何想要使页脚保持固定的想法。
答案 0 :(得分:2)
您必须创建主布局。它有viewpager和页脚 并将片段加载到视图寻呼机。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<!--Header-->
<TextView
android:id="@+id/headerTextViewe"
android:layout_height="50dp"
android:layout_width="match_parent"
android:text="Header"
android:textColor="@android:color/black"
android:textSize="24dip"
android:typeface="sans"
android:layout_gravity="center"
android:layout_centerHorizontal="true"
android:background="@color/background"
android:gravity="center" />
<!--View Pager-->
<android.support.v4.view.ViewPager
android:id="@+id/createTeamViewPager"
android:layout_width="match_parent"
android:layout_height="420dp" />
<!--Footer-->
<Button
android:text="Next"
android:layout_height="50dp"
android:layout_width="match_parent"
android:id="@+id/NextButton"
android:textStyle="bold"
android:textSize="17sp"
android:hint="Next" />
</LinearLayout>
的活动:
public class MyMatches extends AppCompatActivity {
private Toolbar toolbar;
private TabLayout tabLayout;
private ViewPager viewPager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my_teams_master);
iniUI();
setupViewPager(viewPager);
}
`
void iniUI() {
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
viewPager = (ViewPager) findViewById(R.id.viewpager);
tabLayout = (TabLayout) findViewById(R.id.tabs);
}
void setupViewPager(ViewPager viewPager) {
CustomViewPagerFragmentAdapter adapter = new CustomViewPagerFragmentAdapter(getSupportFragmentManager());
CustomListViewFragment fragment1= CustomListViewFragment.newInstance();
CustomListViewFragment fragment2= CustomListViewFragment.newInstance();
adapter.addFragment(fragment1, "Current");
adapter.addFragment(fragment2, "Past");
viewPager.setAdapter(adapter);
tabLayout.setupWithViewPager(viewPager);
getSupportActionBar().setTitle(getResources().getString(R.string.mymatchesitem));
//toolbar.setTitle(getResources().getString(R.string.MyMatchesActivityTitle));
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ActivityCompat.finishAfterTransition(MyMatches.this);
}
});
}
}