在Android中,页脚在ViewPager上是固定的。

3

我有一个页脚,我正在使用它与viewpager一起。当我向左或向右滑动时,页脚也会向左或向右滑动。我希望页脚在每个viewpager页面上都保持固定。有什么想法可以使页脚保持固定,即使我滑动页面。

1个回答

4
您需要创建一个主要布局,其中包含视图分页器和页脚,然后将片段加载到视图分页器中。
<?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);
        }
    });
}

}


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接