W3Cschool
恭喜您成為首批注冊(cè)用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
編寫: kesenhoo - 原文: http://developer.android.com/training/wearables/apps/layouts.html
為可穿戴設(shè)備創(chuàng)建布局是和手持設(shè)備是一樣的,除了我們需要為屏幕的尺寸和glanceability進(jìn)行設(shè)計(jì)。但是不要期望通過搬遷手持應(yīng)用的功能與UI到可穿戴上會(huì)有一個(gè)好的用戶體驗(yàn)。僅僅在有需要的時(shí)候,我們才應(yīng)該創(chuàng)建自定義的布局。請(qǐng)參考可穿戴設(shè)備的design guidelines學(xué)習(xí)如何設(shè)計(jì)一個(gè)優(yōu)秀的可穿戴應(yīng)用。
通常來說,我們應(yīng)該在手持應(yīng)用上創(chuàng)建好notification,然后讓它自動(dòng)同步到可穿戴設(shè)備上。這讓我們只需要?jiǎng)?chuàng)建一次notification,然后可以在不同類型的設(shè)備(不僅僅是可穿戴設(shè)備,也包含車載設(shè)備與電視)上進(jìn)行顯示,免去為不同設(shè)備進(jìn)行重新設(shè)計(jì)。
如果標(biāo)準(zhǔn)的notification風(fēng)格無法滿足我們的需求(例如NotificationCompat.BigTextStyle 或者 NotificationCompat.InboxStyle),我們可以顯示一個(gè)使用自定義布局的activity。我們只可以在可穿戴設(shè)備上創(chuàng)建并處理自定義的notification,同時(shí)系統(tǒng)不會(huì)將這些notification同步到手持設(shè)備上。
Note: 當(dāng)在可穿戴設(shè)備上創(chuàng)建自定義的notification時(shí),我們可以使用標(biāo)準(zhǔn)notification API(API Level 20),不需要使用Support Library。
為了創(chuàng)建自定義的notification,步驟如下:
public void onCreate(Bundle bundle){
...
setContentView(R.layout.notification_activity);
}
Theme.DeviceDefault.Light
。例如:<activity android:name="com.example.MyDisplayActivity"
android:exported="true"
android:allowEmbedded="true"
android:taskAffinity=""
android:theme="@android:style/Theme.DeviceDefault.Light" />
Intent notificationIntent = new Intent(this, NotificationActivity.class);
PendingIntent notificationPendingIntent = PendingIntent.getActivity(this, 0, notificationIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
Note: 當(dāng)notification呈現(xiàn)在主頁(yè)時(shí),系統(tǒng)會(huì)根據(jù)notification的語義,使用一個(gè)標(biāo)準(zhǔn)的模板來呈現(xiàn)它。這個(gè)模板可以在所有的表盤上進(jìn)行顯示。當(dāng)用戶往上滑動(dòng)notification時(shí),將會(huì)看到為這個(gè)notification準(zhǔn)備的自定義的activity。
當(dāng)我們使用Android Studio的工程向?qū)?chuàng)建一個(gè)Wearable應(yīng)用的時(shí)候,會(huì)自動(dòng)包含Wearable UI庫(kù)。你也可以通過給build.gradle
文件添加下面的依賴聲明把庫(kù)文件添加到項(xiàng)目:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.android.support:wearable:+'
compile 'com.google.android.gms:play-services-wearable:+'
}
這個(gè)庫(kù)文件幫助我們建立為可穿戴設(shè)備設(shè)計(jì)的UI。更詳細(xì)的介紹請(qǐng)看為可穿戴設(shè)備創(chuàng)建自定義UI。
下面是一些Wearable UI庫(kù)中主要的類:
這個(gè)參考文獻(xiàn)解釋了如何詳細(xì)地使用每個(gè)UI組件。查看Wear API reference documentation了解上述類的用法。
如果你正在使用Eclipse ADT,那么下載Wearable UI library將Wearable UI庫(kù)導(dǎo)入到你的工程當(dāng)中。
Note: 我們推薦使用Android Studio來開發(fā)可穿戴應(yīng)用。
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: