应用Glass主题
主题包含如下特性:
1、使用Roboto字体
2、全屏显示activity,没有状态栏或action bar
3、填充黑色背景
使用Glass主题,不用在你的Android Manifest中声明。
注意:ADT和 Android Studio 通常会自动分配一个主题,所以在创建一个项目后删除它。
如果你有一个自定义的样式,并又想要使用Glass主题,可以通过parent属性来继承 Theme.DeviceDefault
[XML] 纯文本查看 复制代码
?
01
02
03
04
05
<resources>
<style name="CustomTheme" parent="@android:style/Theme.DeviceDefault">
<!-- Theme customization goes here. -->
</style>
</resources>
创建Glass样式卡片
一个卡片有如下特性:
主体文本
左对齐页脚
一个或多个图像显示作为一个马赛克的背景或卡片的左边
创建和使用卡片 对象:
设置卡片的属性。
调用 Card.toView() 把卡片转换为一个Android View。
在你的activity,布局,或在一个 CardScrollView 中使用的视图 。
下面的示例创建一个文本卡片,全背景图卡片,和一个图像马赛克卡片。
[Java] 纯文本查看 复制代码
?
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<font style="font-size:15px">// 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();</font>
创建activity中的滚动卡片
谷歌眼镜的显示屏和触摸板都是能很好的展现可滑动的卡片,例如谷歌眼镜的时间轴。如果你在构建一个activity,你也能通过CardScrollView 控件来创建出同样的效果样式。
1、实现一个 CardScrollAdapter 应用于CardScrollView . 你能构建一个标准的视图层级 或使用 card 类。
2、创建一个使用了这个CardScrollAdapter的CardScrollView
3、设置你的activity内容视图,或者显示CardScrollView在一个布局里
这有一个滚动三张卡片的简单实现:
[Java] 纯文本查看 复制代码
?
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
public class CardScrollActivity extends Activity {
private List<Card> 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;
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();
}
}
}
本文由穿戴猫论坛原创编译,转载请注明出处。