中心将可滑动标签中的文本对齐

时间:2015-01-09 09:32:53

标签: android

我正在使用Viewpager在Android中实现Swipeable选项卡,如何在选项卡中居中对齐文本。我尝试过使用layout_gravity =" center"但这不起作用。我没有使用TextView。在我使用的Java代码中:

private String[] tabs = { "Action", " Adventure", "Comedy", "Crime",
            "Fantasy", "Historical", "Horror", "Mystery", "Philosophical",
            "Political", "Romance", "Science Fiction", "Thriller",
            "True Story", "Urban" };

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.movie_main);


        // Initilization
        viewPager = (ViewPager) findViewById(R.id.pager);
    //  titleStrip = (PagerTitleStrip)findViewById(R.id.pager_title_strip);
        actionBar = getActionBar();
        mAdapter = new TabsPagerAdapter(getSupportFragmentManager());

        viewPager.setAdapter(mAdapter);
        actionBar.setHomeButtonEnabled(true);

        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

        // Adding Tabs
        for (String tab_name : tabs) {
            actionBar.addTab(actionBar.newTab().setText(tab_name)
                    .setTabListener(this));

        }

        /**
         * on swiping the viewpager make respective tab selected
         * */
        viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

            @Override
            public void onPageSelected(int position) {
                // on changing the page
                // make respected tab selected
                actionBar.setSelectedNavigationItem(position);
            }

            @Override
            public void onPageScrolled(int arg0, float arg1, int arg2) {
            }

            @Override
            public void onPageScrollStateChanged(int arg0) {
            }
        });
    }


<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/pager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"

    >
</android.support.v4.view.ViewPager>

1 个答案:

答案 0 :(得分:0)

在父版面中使用android:orientation="vertical"android:orientation="horizontal"