卷页不工作在操作栏标签 [英] Page curl not working in Action bar tabs

查看:122
本文介绍了卷页不工作在操作栏标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  • 我提到的 Harism 页面卷曲在操作栏来实现它 tabs.Because我认为这是唯一应当满足我的要求。

  • 下面我显示在输出我得到它到现在。

  • 我需要添加寻呼机卷曲Viewpager.So的动作栏选项卡 将刷卡以及卷曲的页面。

  • 下面我贴codeS相关的。

MainActivity.java:

 公共类MainActivity扩展FragmentActivity工具
        ActionBar.TabListener {

    私人CurlView mCurlView;


    私人ViewPager viewPager;
    私人TabsPagerAdapter mAdapter;
    私人ActionBar的动作条;

    @燮pressWarnings(未使用)
    私人菜单optionsMenu;
    私人菜单项菜单项;

    //标签标题
    私有String []选项卡= {最高评分,游戏,电影};

    @燮pressWarnings(德precation)
    @燮pressLint(NewApi)
    @覆盖
    保护无效的onCreate(包savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.activity_main);

        INT索引= 0;
        如果(getLastNonConfigurationInstance()!= NULL){
            指数=(整数)getLastNonConfigurationInstance();
        }

        mCurlView =(CurlView)findViewById(R.id.curl);
        mCurlView.setPageProvider(新PageProvider());
        mCurlView.setSizeChangedObserver(新SizeChangedObserver());
        mCurlView.setCurrentIndex(指数);
        mCurlView.setBackgroundColor(0xFF202830);

        //动初始化
        viewPager =(ViewPager)findViewById(R.id.pager);
        动作条= getActionBar();
        mAdapter =新TabsPagerAdapter(getSupportFragmentManager());

        viewPager.setAdapter(mAdapter);
        actionBar.setHomeButtonEnabled(假);
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);


        actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME
                | ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_SHOW_CUSTOM);

        //添加标签
        对于(字符串TAB_NAME:标签){
            actionBar.addTab(actionBar.newTab()的setText(TAB_NAME)
                    .setTabListener(本));
        }

        / **
         *上刷卡viewpager做出相应的选项卡中选择
         * * /
        viewPager.setOnPageChangeListener(新ViewPager.OnPageChangeListener(){

            @覆盖
            公共无效onPageSelected(INT位置){
                //在改变页面
                //使尊敬的选项卡中选择
                actionBar.setSelectedNavigationItem(位置);

            }

            @覆盖
            公共无效onPageScrolled(INT为arg0,浮动ARG1,ARG2 INT){
            }

            @覆盖
            公共无效onPageScrollStateChanged(INT为arg0){
            }
        });

    }

    @覆盖
    公共无效的onPause(){
        super.onPause();
        mCurlView.onPause();
    }

    @覆盖
    公共无效onResume(){
        super.onResume();
        mCurlView.onResume();
    }

    @覆盖
    公共对象getLastCustomNonConfigurationInstance(){
        返回mCurlView.getCurrentIndex();
    }

        / **
        *位图提供商。
        * /
        私有类PageProvider实现CurlView.PageProvider {

            //位图资源。
        私人INT [] mBitmapIds = {R.layout.fragment_top_rated,R.layout.fragment_games,
            R.layout.fragment_movies};

        @覆盖
        公众诠释getPageCount(){
        返回2;
        }
        私人位图loadBitmap(INT宽度,高度INT,INT指数){
            LayoutInflater充气=(LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);

            Log.d(指数,将String.valueOf(指数));
            视图V = inflater.inflate(mBitmapIds [指数],NULL);
            v.measure(MeasureSpec.makeMeasureSpec(宽,MeasureSpec.EXACTLY)
                    MeasureSpec.makeMeasureSpec(高度,MeasureSpec.EXACTLY));
            v.layout(0,0,v.getMeasuredWidth(),v.getMeasuredHeight());
            位图B = Bitmap.createBitmap(v.getWidth(),v.getHeight(),
                    Bitmap.Config.ARGB_8888);
            帆布C =新的Canvas(B);
            v.draw(C);
            返回b;
        }

        @覆盖
        公共无效的updatePage(CurlPage页,诠释的宽度,高度INT,INT指数){

            开关(指数){
            //第一种情况是形象正面,纯色回来。
            默认:

                位图前方= loadBitmap(宽度,高度,0);
                page.setTexture(前,CurlPage.SIDE_FRONT);
                page.setColor(Color.rgb(180,180,180),CurlPage.SIDE_BACK);
                打破;

            }
        }
    }

    / **
     * CurlView大小变化的观察。
     * /
    私有类SizeChangedObserver实现CurlView.SizeChangedObserver {
        @覆盖
        公共无效onSizeChanged(INT W,INT高){
            如果(并且R w; H){
                mCurlView.setViewMode(CurlView.SHOW_TWO_PAGES);
                mCurlView.setMargins(.1F,.05f,.1F,.05f);
            } 其他 {
                mCurlView.setViewMode(CurlView.SHOW_ONE_PAGE);
                // mCurlView.setMargins(.1F,.1F,.1F,.1F);
            }
        }
    }

    }
 

activity_main.xml:

 < XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent
    机器人:方向=垂直>

    < info.androidhive.tabsswipe.adapter.CurlView
        的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
        机器人:ID =@ + ID /卷曲
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =FILL_PARENT>
    < /info.androidhive.tabsswipe.adapter.CurlView>

    < android.support.v4.view.ViewPager
        机器人:ID =@ + ID /寻呼机
        机器人:layout_width =match_parent
        机器人:layout_height =match_parent>
    < /android.support.v4.view.ViewPager>

< / LinearLayout中>
 

TopRatedFragment.java:

 公共类TopRatedFragment扩展片段{

    @覆盖
    公共查看onCreateView(LayoutInflater充气,容器的ViewGroup,
            捆绑savedInstanceState){

        查看rootView = inflater.inflate(R.layout.fragment_top_rated,集装箱,假);

        返回rootView;
    }
}
 

fragment_top_rated.xml:

 < XML版本=1.0编码=UTF-8&GT?;
< RelativeLayout的的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent
    机器人:后台=#fa6a6a
    机器人:方向=垂直>

    <的TextView
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_centerInParent =真
        机器人:重力=中心
        机器人:文本=设计最高评分屏幕
        机器人:TEXTSIZE =20dp/>

< / RelativeLayout的>
 

TabsPagerAdapter.java:

 进口info.androidhive.tabsswipe.GamesFragment;
进口info.androidhive.tabsswipe.MoviesFragment;
进口info.androidhive.tabsswipe.TopRatedFragment;
进口android.support.v4.app.Fragment;
进口android.support.v4.app.FragmentManager;
进口android.support.v4.app.FragmentPagerAdapter;

公共类TabsPagerAdapter扩展FragmentPagerAdapter {

    公共TabsPagerAdapter(FragmentManager FM){
        超(FM);
    }

    @覆盖
    公共片段的getItem(INT指数){

        开关(指数){
        情况下0:
            //最高评分片段活动

            返回新TopRatedFragment();
        情况1:
            //游戏片段活动
            返回新GamesFragment();
        案例2:
            //电影片段活动
            返回新MoviesFragment();
        }

        返回null;
    }

    @覆盖
    公众诠释getCount将(){
        //获取项目计数 - 等于标签数
        返回3;
    }

}
 

我的问题是我需要添加的页面卷曲ViewPager.So,我可以做的刷卡随着viewpager.I不知道该怎么办that.But我试图让it.Any的建议大多是AP preciated.Thank你。<​​/ P>

解决方案

Harism的页面卷曲是专为位图,而不是观点。通过该模块,这是不可能达到你想要什么,除非你的卡只包含的位图

  • I am referred the Harism page curl to implement it in Action bar tabs.Because I thought this is the only thing should fulfill my requirement.

  • Below I am showing the output what I get it till now.

  • I need to add the pager curl in Viewpager.So that the action bar tabs will swipe along with curl page.

  • Below I am posted the codes related to that.

MainActivity.java:

public class MainActivity extends FragmentActivity implements
        ActionBar.TabListener {

    private CurlView mCurlView;


    private ViewPager viewPager;
    private TabsPagerAdapter mAdapter;
    private ActionBar actionBar;

    @SuppressWarnings("unused")
    private Menu optionsMenu;
    private MenuItem menuItem;

    // Tab titles
    private String[] tabs = { "Top Rated", "Games", "Movies" };

    @SuppressWarnings("deprecation")
    @SuppressLint("NewApi")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);     

        int index = 0;
        if (getLastNonConfigurationInstance() != null) {
            index = (Integer) getLastNonConfigurationInstance();
        }

        mCurlView = (CurlView) findViewById(R.id.curl);
        mCurlView.setPageProvider(new PageProvider());
        mCurlView.setSizeChangedObserver(new SizeChangedObserver());
        mCurlView.setCurrentIndex(index);
        mCurlView.setBackgroundColor(0xFF202830);

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

        viewPager.setAdapter(mAdapter);
        actionBar.setHomeButtonEnabled(false);
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);


        actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME
                | ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_SHOW_CUSTOM);

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

    }

    @Override
    public void onPause() {
        super.onPause();
        mCurlView.onPause();
    }

    @Override
    public void onResume() {
        super.onResume();
        mCurlView.onResume();
    }

    @Override
    public Object getLastCustomNonConfigurationInstance() {
        return mCurlView.getCurrentIndex();
    }

        /**
        * Bitmap provider.
        */
        private class PageProvider implements CurlView.PageProvider {

            // Bitmap resources.
        private int[] mBitmapIds = { R.layout.fragment_top_rated, R.layout.fragment_games,
            R.layout.fragment_movies };

        @Override
        public int getPageCount() {
        return 2;
        }
        private Bitmap loadBitmap(int width, int height, int index) {
            LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);

            Log.d("index", String.valueOf(index));
            View v = inflater.inflate(mBitmapIds[index], null);
            v.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY),
                    MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
            v.layout(0, 0, v.getMeasuredWidth(), v.getMeasuredHeight());
            Bitmap b = Bitmap.createBitmap(v.getWidth(), v.getHeight(),
                    Bitmap.Config.ARGB_8888);
            Canvas c = new Canvas(b);
            v.draw(c);
            return b;
        }

        @Override
        public void updatePage(CurlPage page, int width, int height, int index) {

            switch (index) {
            // First case is image on front side, solid colored back.
            default:

                Bitmap front = loadBitmap(width, height, 0);
                page.setTexture(front, CurlPage.SIDE_FRONT);
                page.setColor(Color.rgb(180, 180, 180), CurlPage.SIDE_BACK);
                break;

            }
        }
    }

    /**
     * CurlView size changed observer.
     */
    private class SizeChangedObserver implements CurlView.SizeChangedObserver {
        @Override
        public void onSizeChanged(int w, int h) {
            if (w > h) {
                mCurlView.setViewMode(CurlView.SHOW_TWO_PAGES);
                mCurlView.setMargins(.1f, .05f, .1f, .05f);
            } else {
                mCurlView.setViewMode(CurlView.SHOW_ONE_PAGE);
                // mCurlView.setMargins(.1f, .1f, .1f, .1f);
            }
        }
    }

    }

activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <info.androidhive.tabsswipe.adapter.CurlView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/curl"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >
    </info.androidhive.tabsswipe.adapter.CurlView>

    <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    </android.support.v4.view.ViewPager>

</LinearLayout>

TopRatedFragment.java:

public class TopRatedFragment extends Fragment {

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {

        View rootView = inflater.inflate(R.layout.fragment_top_rated, container, false);

        return rootView;
    }
}

fragment_top_rated.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#fa6a6a"
    android:orientation="vertical" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:gravity="center"
        android:text="Design Top Rated Screen"
        android:textSize="20dp" />

</RelativeLayout>

TabsPagerAdapter.java:

import info.androidhive.tabsswipe.GamesFragment;
import info.androidhive.tabsswipe.MoviesFragment;
import info.androidhive.tabsswipe.TopRatedFragment;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

public class TabsPagerAdapter extends FragmentPagerAdapter {

    public TabsPagerAdapter(FragmentManager fm) {
        super(fm);
    }

    @Override
    public Fragment getItem(int index) {

        switch (index) {
        case 0:
            // Top Rated fragment activity

            return new TopRatedFragment();
        case 1:
            // Games fragment activity
            return new GamesFragment();
        case 2:
            // Movies fragment activity
            return new MoviesFragment();
        }

        return null;
    }

    @Override
    public int getCount() {
        // get item count - equal to number of tabs
        return 3;
    }

}

My issue is I need to add the page curl in ViewPager.So that I can do the swipe along with viewpager.I didn't know how to do that.But I am trying to get it.Any suggestion is mostly appreciated.Thank you.

解决方案

Harism's page curl is designed for bitmaps, not for views. With that module, it is not possible to reach what you want, unless your tab contains only bitmaps

这篇关于卷页不工作在操作栏标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆