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

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




应用Glass主题


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


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


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




[html] view plain copy 在CODE上查看代码片 派生到我的代码片
  1. <resources>

  2. <stylename="CustomTheme"parent="@android:style/Theme.DeviceDefault">

  3. <!-- Theme customization goes here. -->

  4. </style>

  5. </resources>






创建Glass样式卡片


一个卡片有如下特性:



・        主体文本

・        左对齐页脚

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





创建和使用卡片对象:

1.   设置卡片的属性。

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

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




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


082206h6jxi3fmifzjmmis.png



[java] view plain copy 在CODE上查看代码片 派生到我的代码片
  1. <font style="font-size:15px">// Create a card with some simple text and a footer.

  2. Card card1 = new Card(context);  

  3. card1.setText("This card has a footer.");  

  4. card1.setFootnote("I'm the footer!");  

  5. // Don't call this if you're using TimelineManager

  6. View card1View = card1.toView();  

  7. // Create a card with a full-screen background image.

  8. Card card2 = new Card(context);  

  9. card2.setText("This card has a puppy background image.");  

  10. card2.setFootnote("How can you resist?");  

  11. card2.setImageLayout(Card.ImageLayout.FULL);  

  12. card2.addImage(R.drawable.puppy_bg);  

  13. // Don't call this if you're using TimelineManager

  14. View card2View = card2.toView();  

  15. // Create a card with multiple images displayed as a mosaic.

  16. Card card3 = new Card(context);  

  17. card3.setText("This card has a mosaic of puppies.");  

  18. card3.setFootnote("Aren't they precious?");  

  19. card3.setImageLayout(Card.ImageLayout.LEFT);  

  20. card3.addImage(R.drawable.puppy_small_1);  

  21. card3.addImage(R.drawable.puppy_small_2);  

  22. card3.addImage(R.drawable.puppy_small_3);  

  23. // Don't call this if you're using TimelineManager

  24. View card3View = card3.toView();</font>  






创建activity中的滚动卡片

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

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

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

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



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


[java] view plain copy 在CODE上查看代码片 派生到我的代码片
  1. publicclass CardScrollActivity extends Activity {  

  2. private List<Card> mCards;  

  3. private CardScrollView mCardScrollView;  

  4. @Override

  5. protectedvoid onCreate(Bundle savedInstanceState) {  

  6. super.onCreate(savedInstanceState);  

  7.        createCards();  

  8.        mCardScrollView = new CardScrollView(this);  

  9.        ExampleCardScrollAdapter adapter = new ExampleCardScrollAdapter();  

  10.        mCardScrollView.setAdapter(adapter);  

  11.        mCardScrollView.activate();  

  12.        setContentView(mCardScrollView);  

  13.    }  

  14. privatevoid createCards() {  

  15.        mCards = new ArrayList<Card>();  

  16.        Card card;  

  17.        card = new Card(this);  

  18.        card.setText("This card has a footer.");  

  19.        card.setFootnote("I'm the footer!");  

  20.        mCards.add(card);  

  21.        card = new Card(this);  

  22.        card.setText("This card has a puppy background image.");  

  23.        card.setFootnote("How can you resist?");  

  24.        card.setImageLayout(Card.ImageLayout.FULL);  

  25.        card.addImage(R.drawable.puppy_bg);  

  26.        mCards.add(card);  

  27.        card = new Card(this);  

  28.        card.setText("This card has a mosaic of puppies.");  

  29.        card.setFootnote("Aren't they precious?");  

  30.        card.setImageLayout(Card.ImageLayout.LEFT);  

  31.        card.addImage(R.drawable.puppy_small_1);  

  32.        card.addImage(R.drawable.puppy_small_2);  

  33.        card.addImage(R.drawable.puppy_small_3);  

  34.        mCards.add(card);  

  35.    }  

  36. privateclass ExampleCardScrollAdapter extends CardScrollAdapter {  

  37. @Override

  38. publicint findIdPosition(Object id) {  

  39. return -1;  

  40.        }  

  41. @Override

  42. publicint findItemPosition(Object item) {  

  43. return mCards.indexOf(item);  

  44.        }  

  45. @Override

  46. publicint getCount() {  

  47. return mCards.size();  

  48.        }  

  49. @Override

  50. public Object getItem(int position) {  

  51. return mCards.get(position);  

  52.        }  

  53. @Override

  54. public View getView(int position, View convertView, ViewGroup parent) {  

  55. return mCards.get(position).toView();  

  56.        }  

  57.    }  

  58. }  



你可能感兴趣的:(android,Activity,action,谷歌,parent)