1

I am trying to add a custom layout page within cards.

Here: https://developer.android.com/training/wearables/ui/2d-picker.html

explains that CardFragment can easily add a card by:

CardFragment fragment = CardFragment.create(title, text, page.iconRes);

now if I decided I want to have a custom layout, how do I add it instead of creating a CardFragment?

Check this image:

enter image description here

The third page is a full screen custom layout. How can I achieve this?

lxg
  • 12,375
  • 12
  • 51
  • 73
MoGa
  • 635
  • 6
  • 14

3 Answers3

3

FragmentGridPagerAdapter can actually support any subclass of Fragment that you need to use. CardFragment is just a convenience for a standard wearable layout.

So, you can just create a custom Fragment with a simple layout (such as a full-size ImageView) and return it for the appropriate page index.

matiash
  • 54,791
  • 16
  • 125
  • 154
2

On getFragment(int row, int col) method from your FragmentGridPagerAdapter class, you can create as many fragments as you want.

you just need to test your row/col values in order to instantiate your fragment class in the correct position.

In your case, something like this:

public Fragment getFragment(int row, int col) {

    Fragment fragment;
    if (row == 0 && col == 2) {
        fragment = new YourFullScreenFragment();
    } else {
        fragment = CardFragment.create(title, text, page.iconRes);
    }

    return fragment;

}

Cheers

Leonardo
  • 228
  • 3
  • 10
0

CardFrame is probably that one that you are looking for - it very similar to CardFragment but you can implement your own layout to it. Also as matiash pointed you can use any fragment that you like in such structure.

Michał Tajchert
  • 10,333
  • 4
  • 30
  • 47