简体   繁体   English

如何创建不带卡的全屏Android Wear应用

[英]How to create a full screen Android Wear app without cards

I'm brand new to Android programming and I'm trying to create a full screen Android Wear interface with custom layouts and no cards. 我是Android编程的新手,我正在尝试创建一个具有自定义布局且没有卡片的全屏Android Wear界面。 I'm trying to go off the sample but I can't figure out how to get around using CardFragments. 我正在尝试通过示例,但我不知道如何使用CardFragments。 My MainActivity code is essentially identical to the example, with a few names changed. 我的MainActivity代码本质上与示例相同,只是更改了一些名称。 Here is the code for my GridViewPagerAdaper: 这是我的GridViewPagerAdaper的代码:

public class MyGridViewPagerAdapter extends FragmentGridPagerAdapter {

private final Context mContext;

public MyGridViewPagerAdapter(Context ctx, FragmentManager fm) {
    super(fm);
    mContext = ctx;
}

static final int[] BG_IMAGES = new int[]{
        R.drawable.bg,
};

/**
 * A simple container for static data in each page
 */
private static class Page {
    int titleRes;
    int textRes;
    int iconRes;
    int cardGravity = Gravity.BOTTOM;
    boolean expansionEnabled = true;
    float expansionFactor = 1.0f;
    int expansionDirection = CardFragment.EXPAND_DOWN;


    public Page(int titleRes) {
        this.titleRes = titleRes;
        this.textRes = textRes;
        this.iconRes = iconRes;
    }

    public Page(int titleRes, int textRes, int iconRes, int gravity) {
        this.titleRes = titleRes;
        this.textRes = textRes;
        this.iconRes = iconRes;
        this.cardGravity = gravity;
    }
}

private final Page[][] PAGES = {
        {
                new Page(R.drawable.tuner),
        },
        {
                new Page(R.drawable.metronome),
                new Page(R.drawable.metroplain)
        },
};
@Override

public Fragment getFragment(int row, int col) {
    Page page = PAGES[row][col];
//        String title = page.titleRes != 0 ? mContext.getString(page.titleRes) : null;
//        String text = page.textRes != 0 ? mContext.getString(page.textRes) : null;
    CardFragment fragment = CardFragment.create("", "", page.iconRes);
    // Advanced settings
    fragment.setCardGravity(page.cardGravity);
    fragment.setExpansionEnabled(page.expansionEnabled);
    fragment.setExpansionDirection(page.expansionDirection);
    fragment.setExpansionFactor(page.expansionFactor);
    return fragment;
}

@Override
public ImageReference getBackground(int row, int column) {
    return ImageReference.forDrawable(BG_IMAGES[row % BG_IMAGES.length]);
}

@Override
public int getRowCount() {
    return PAGES.length;
}

@Override
public int getColumnCount(int rowNum) {
    return PAGES[rowNum].length;
  }
}

What's the best way to get rid of the cards and use a custom layout? 摆脱卡片并使用自定义布局的最佳方法是什么? Thanks for your help. 谢谢你的帮助。

In your adapter, give your fragments as following: 在您的适配器中,按如下所示分配片段:

private final Activity mContext;
private final Fragment[][] mFragment;

public MyGridViewPagerAdapter(Activity ctx, FragmentManager fm, Fragment[][] fragments)
{
  super(fm);
  mContext = ctx;
  this.mFragment = fragments;
}

then override the following methods: 然后覆盖以下方法:

@Override
public Fragment getFragment(int row, int col) 
{ 
  return mFragment[row][col]; 
}

@Override
public int getRowCount() 
{ 
  return mFragment.length; 
}

@Override
public int getColumnCount(int rowNum) 
{ 
  return mFragment[rowNum].length; 
}

then in your activity do as following: 然后在您的活动中执行以下操作:

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

  final GridViewPager pager = (GridViewPager) findViewById(R.id.pager);
  final Fragment[][] items = {
        {
                CusmtomFragment.newInstance("your","arguments"),
                CusmtomFragment.newInstance()
        },
        {
                OtherFragment.newInstance(),
                AnotherFragment.newInstance(1234)
        }
  };
  // ....
  pager.setAdapter(new MyGridViewPagerAdapter(this, getFragmentManager(), items));
}

Hope it helps ! 希望能帮助到你 !

If you implement a custom wearable app you can do what you want including a custom UI. 如果您实现了自定义可穿戴应用程序,则可以执行所需的操作,包括自定义UI。

The problems are more to Is there any way to detect if the clock is round? 问题不仅仅在于是否有任何方法可以检测时钟是否为圆形?

Or how to start the app you n the wearable. 或如何启动可穿戴式应用程序。 This is done with a special service. 这是一项特殊服务。 Basically you is the dataApi for that. 基本上,您就是该用户的dataApi。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM