2

I seen many github related to page curl.I mentioned it below:

  1. harism
  2. openaphid
  3. mediafire
  4. MysticTreeGames

But everything is related to Images.It wasn't working for me.I need to implement page curl in Action bar tabs.

For Eg: I am posted the example image below for page curl in action bar tabs.

enter image description here

Below I am posted the codes for Action bar tabs:

MainActivity.java:

  public class MainActivity extends FragmentActivity implements
        ActionBar.TabListener {

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

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

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

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

    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 onTabReselected(Tab tab, FragmentTransaction ft) {
    }

    @Override
    public void onTabSelected(Tab tab, FragmentTransaction ft) {
        // on tab selected
        // show respected fragment view
        viewPager.setCurrentItem(tab.getPosition());
    }

    @Override
    public void onTabUnselected(Tab tab, FragmentTransaction ft) {
    }

}

activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>

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

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>

Edited: I am already tried in Action bar tabs.But it is Working in Activity not in Fragments(Action bar tabs).

If I get some tutorials or github or some samples or any other suggestion related to implementing page curl in action bar tabs.That will be helpful to me .Thank you.

Community
  • 1
  • 1
Stephen
  • 9,899
  • 16
  • 90
  • 137

2 Answers2

1

If you can get the content that you wish to page curl, into a View instance, then any curl effect that uses Bitmap instances could potentially be used if you render the Views onto Bitmaps. A method like this could be used:

public Bitmap renderViewAsBitmap( View view ) {
    view.setDrawingCacheEnabled( true );
    view.buildDrawingCache();
    return view.getDrawingCache();
}

Or if you want to do more manipulation of the image prior to the curl effect:

public Bitmap renderViewAsBitmap( View view, int width, int height ) {
    Bitmap bitmap = Bitmap.createBitmap( width, height, Bitmap.Config.ARGB_8888 );
    Canvas canvas = new Canvas( bitmap );
    view.draw( canvas );
    return bitmap;
}

Layouts can

I'll try and write up a test case that using action bar tabs for reference, and will edit this answer with more sample code.

paulscode
  • 1,049
  • 1
  • 12
  • 29
0

The stock android tabs belongs to the Actionbar. They are rendered outside the main fragment (the one below the Actionbar). Since you are applying your curl effect in your fragments, you'll never see it happening in the tabs.

I suggest you use libraries that simulates the same behaviour of actionbar tabs (e.g PageSlidingTabStrip) thats forces you to add a your tabs inside your views. After adding your tabs inside your views with those custom libraries try applying your curl effect.

Thiago M Rocha
  • 1,416
  • 1
  • 20
  • 26
  • I am worked in PageSlidingTabStrip.But I am not implemented the page curl in that.Ok Let me try and tell you. – Stephen Dec 03 '14 at 03:51