谷歌眼镜Mirror API开发指南之Glass主题和UI控件

原文地址:http://bbs.seacat.cn/thread-895-1-2.html



应用Glass主题


主题包含如下特性:
1、使用Roboto字体
2、全屏显示activity,没有状态栏或action bar
3、填充黑色背景


使用Glass主题,不用在你的Android Manifest中声明。
注意:ADT Android Studio 通常会自动分配一个主题,所以在创建一个项目后删除它。


如果你有一个自定义的样式,并又想要使用Glass主题,可以通过parent属性来继承 Theme.DeviceDefault 




    



创建Glass样式卡片


一个卡片有如下特性:



·        主体文本

·        左对齐页脚

·        一个或多个图像显示作为一个马赛克的背景或卡片的左边





创建和使用卡片对象:

1.   设置卡片的属性。

2.   调用 Card.toView()把卡片转换为一个Android View

3.   在你的activity,布局,或在一个 CardScrollView 中使用的视图 




下面的示例创建一个文本卡片,全背景图卡片,和一个图像马赛克卡片。




// Create a card with some simple text and a footer.
Card card1 = new Card(context);
card1.setText("This card has a footer.");
card1.setFootnote("I'm the footer!");
// Don't call this if you're using TimelineManager
View card1View = card1.toView();
 
// Create a card with a full-screen background image.
Card card2 = new Card(context);
card2.setText("This card has a puppy background image.");
card2.setFootnote("How can you resist?");
card2.setImageLayout(Card.ImageLayout.FULL);
card2.addImage(R.drawable.puppy_bg);
// Don't call this if you're using TimelineManager
View card2View = card2.toView();
 
// Create a card with multiple images displayed as a mosaic.
Card card3 = new Card(context);
card3.setText("This card has a mosaic of puppies.");
card3.setFootnote("Aren't they precious?");
card3.setImageLayout(Card.ImageLayout.LEFT);
card3.addImage(R.drawable.puppy_small_1);
card3.addImage(R.drawable.puppy_small_2);
card3.addImage(R.drawable.puppy_small_3);
// Don't call this if you're using TimelineManager
View card3View = card3.toView();



创建activity中的滚动卡片

 

谷歌眼镜的显示屏和触摸板都是能很好的展现可滑动的卡片,例如谷歌眼镜的时间轴。如果你在构建一个activity,你也能通过CardScrollView 控件来创建出同样的效果样式。

1、实现一个 CardScrollAdapter 应用于CardScrollView . 你能构建一个标准的视图层级 或使用 card 类。

2、创建一个使用了这个CardScrollAdapterCardScrollView

3、设置你的activity内容视图,或者显示CardScrollView在一个布局里



这有一个滚动三张卡片的简单实现:


public class CardScrollActivity extends Activity {
 
    private List mCards;
    private CardScrollView mCardScrollView;
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
 
        createCards();
 
        mCardScrollView = new CardScrollView(this);
        ExampleCardScrollAdapter adapter = new ExampleCardScrollAdapter();
        mCardScrollView.setAdapter(adapter);
        mCardScrollView.activate();
        setContentView(mCardScrollView);
    }
 
    private void createCards() {
        mCards = new ArrayList();
 
        Card card;
 
        card = new Card(this);
        card.setText("This card has a footer.");
        card.setFootnote("I'm the footer!");
        mCards.add(card);
 
        card = new Card(this);
        card.setText("This card has a puppy background image.");
        card.setFootnote("How can you resist?");
        card.setImageLayout(Card.ImageLayout.FULL);
        card.addImage(R.drawable.puppy_bg);
        mCards.add(card);
 
        card = new Card(this);
        card.setText("This card has a mosaic of puppies.");
        card.setFootnote("Aren't they precious?");
        card.setImageLayout(Card.ImageLayout.LEFT);
        card.addImage(R.drawable.puppy_small_1);
        card.addImage(R.drawable.puppy_small_2);
        card.addImage(R.drawable.puppy_small_3);
        mCards.add(card);
    }
 
    private class ExampleCardScrollAdapter extends CardScrollAdapter {
 
        @Override
        public int findIdPosition(Object id) {
            return -1;
        }
 
        @Override
        public int findItemPosition(Object item) {
            return mCards.indexOf(item);
        }
 
        @Override
        public int getCount() {
            return mCards.size();
        }
 
        @Override
        public Object getItem(int position) {
            return mCards.get(position);
        }
 
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            return mCards.get(position).toView();
        }
    }
}



你可能感兴趣的:(谷歌眼镜)