Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android TabLayout屏幕底部的位置_Android_Android Tablayout_Android Support Design - Fatal编程技术网

Android TabLayout屏幕底部的位置

Android TabLayout屏幕底部的位置,android,android-tablayout,android-support-design,Android,Android Tablayout,Android Support Design,我正在使用android.support.design.widget,我需要在屏幕底部的activity\u main.xml中设置TabLayout的位置 我知道你可以使用TabHost,但我更喜欢使用android.support.design ativity\u main.xml <android.support.design.widget.AppBarLayout android:layout_width="match_parent" android:layout_

我正在使用android.support.design.widget,我需要在屏幕底部
activity\u main.xml
中设置TabLayout的位置

我知道你可以使用TabHost,但我更喜欢使用android.support.design

ativity\u main.xml

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

    <android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="@dimen/custom_tab_layout_height"
        app:tabMode="fixed"
        app:tabGravity="fill"/>
</android.support.design.widget.AppBarLayout>

<android.support.v4.view.ViewPager
    android:id="@+id/viewpager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />


MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    viewPager = (ViewPager) findViewById(R.id.viewpager);
    setupViewPager(viewPager);

    tabLayout = (TabLayout) findViewById(R.id.tabs);
    tabLayout.setupWithViewPager(viewPager);


    TextView tabOne = (TextView) LayoutInflater.from(this).inflate(R.layout.custom_tab, null);
    tabOne.setText("ONE");
    tabOne.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.ic_tab_call, 0, 0);
    tabLayout.getTabAt(0).setCustomView(tabOne);


    TextView tabTwo = (TextView) LayoutInflater.from(this).inflate(R.layout.custom_tab, null);
    tabTwo.setText("TWO");
    tabTwo.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.iconos, 0, 0);
    tabLayout.getTabAt(1).setCustomView(tabTwo);

}

private void setupViewPager(ViewPager viewPager) {
    ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager());
    adapter.addFrag(new OneFragment(), "");
    adapter.addFrag(new TwoFragment(), "");
    adapter.addFrag(new ThreeFragment(), "");
    viewPager.setAdapter(adapter);
}

class ViewPagerAdapter extends FragmentPagerAdapter {
    private final List<Fragment> mFragmentList = new ArrayList<>();
    private final List<String> mFragmentTitleList = new ArrayList<>();

    public ViewPagerAdapter(FragmentManager manager) {
        super(manager);
    }

    @Override
    public Fragment getItem(int position) {
        return mFragmentList.get(position);
    }

    @Override
    public int getCount() {
        return mFragmentList.size();
    }

    public void addFrag(Fragment fragment, String title) {
        mFragmentList.add(fragment);
        mFragmentTitleList.add(title);
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return mFragmentTitleList.get(position);
    }
}
@覆盖
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
viewPager=(viewPager)findViewById(R.id.viewPager);
设置viewPager(viewPager);
tabLayout=(tabLayout)findViewById(R.id.tabs);
tabLayout.setupWithViewPager(viewPager);
TextView tabOne=(TextView)LayoutInflater.from(this).flate(R.layout.custom_tab,null);
tabOne.setText(“一”);
tabOne.setCompoundDrawablesWithIntrinsicBounds(0,R.drawable.ic_tab_调用,0,0);
tabLayout.getTabAt(0.setCustomView(tabOne);
TextView tabTwo=(TextView)LayoutInflater.from(this).flate(R.layout.custom_tab,null);
tabTwo.setText(“两个”);
tabTwo.setCompoundDrawablesWithIntrinsicBounds(0,R.drawable.iconos,0,0);
tabLayout.getTabAt(1).setCustomView(tabTwo);
}
专用无效设置ViewPager(ViewPager ViewPager){
ViewPagerAdapter适配器=新的ViewPagerAdapter(getSupportFragmentManager());
addFrag(新的OneFragment(),“”);
addFrag(新的TwoFragment(),“”);
addFrag(新的ThreeFragment(),“”);
viewPager.setAdapter(适配器);
}
类ViewPagerAdapter扩展了FragmentPagerAdapter{
私有最终列表MFFragmentList=new ArrayList();
私有最终列表MFFragmentTitleList=new ArrayList();
公共视图页面编辑器(碎片管理器){
高级经理;
}
@凌驾
公共片段getItem(int位置){
返回MFFragmentList.get(位置);
}
@凌驾
public int getCount(){
返回MFFragmentList.size();
}
public void addFrag(片段、字符串标题){
添加(片段);
MFFragmentTitleList.add(标题);
}
@凌驾
公共字符序列getPageTitle(int位置){
返回MFFragmentTitleList.get(位置);
}
}
有什么想法吗?
谢谢。

我的表格布局在线性布局内,如下图所示,给出了线性布局的“底部”tp重力,这就是我在课堂上使用它的方式


    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
    </android.support.design.widget.AppBarLayout>

    <android.support.v4.view.ViewPager
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="460dp"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="80dp"
        android:layout_gravity="bottom"
        android:gravity="center">

        <android.support.design.widget.TabLayout
            android:id="@+id/tablayout_home"
            android:layout_width="match_parent"
            android:layout_height="80dp"
            app:tabGravity="fill"
            app:tabMode="fixed" />


    </LinearLayout>
</android.support.design.widget.CoordinatorLayout>