首頁 > 評(píng)測(cè) > Android Things 之八——在樹莓派3上探索GUI初步
Android Things 之八——在樹莓派3上探索GUI初步
- [導(dǎo)讀]
- Android Things是有GUI的。雖然前面介紹Android Things時(shí),我們都直接使用了Android Studio的Logcat窗口來輸出相關(guān)的信息,但是從現(xiàn)在起,我們開始來探索Android Things的GUI世界。
Android Things是有GUI的。雖然前面介紹 Android Things時(shí),我們都直接使用了Android Studio的Logcat窗口來輸出相關(guān)的信息,但是從現(xiàn)在起,我們開始來探索 Android Things的GUI世界。
歡迎加入Android Things交流群:452863046
i.MX7D支持連接配套的屏幕來輸出,不過RPI3本身提供了HDMI輸出接口,可以直接連接外部顯示器,至于觸摸等輸入功能,使用USB鍵盤和鼠標(biāo)就搞定。
像平常使用RPI3一樣,給它連接好顯示器及鍵盤、鼠標(biāo),只不過這次軟件平臺(tái)變成了 Android Things,神奇的RPI!
上電后我們會(huì)看到什么呢?
上電啟動(dòng)過程中可以看到 Android Things的Logo,等系統(tǒng)完全啟動(dòng)后,就看到了所謂的桌面了。和Android的桌面不同的是,這個(gè)桌面有點(diǎn)寒酸!這個(gè)桌面幾乎沒有交互特性,更多的是提供平臺(tái)的一些描述性的介紹,包括的信息主要有:軟件平臺(tái)、網(wǎng)絡(luò)接口、IO/Pinout及顯示器相關(guān)信息。例如我們知道這是 Android Things的RPI3版本,網(wǎng)絡(luò)地址為192.168.88.21等信息。
這里顯示連接使用的有Ethernet網(wǎng)絡(luò)接口。
硬件平臺(tái)提供的可用I/O接口,包括PWMx2,UARTx2,I2Cx1,SPIx2及全部可用的GPIO編號(hào)等信息。
顯示設(shè)備的分辨率及DPI信息,這里直接使用了顯示器來輸出。
這里顯示的是操作系統(tǒng)的信息,使用的API Level為27,也就是普通意義上的Oreo。另外系統(tǒng)使用的日期格式也可以在這里設(shè)置。
Android Things支持在線升級(jí),如果開發(fā)商升級(jí)了系統(tǒng)固件,可以直接在這里進(jìn)行更新,很是方便!
另外兩個(gè)功能是重啟設(shè)備及恢復(fù)出廠設(shè)置操作,在Android設(shè)備中,這兩個(gè)操作也是非常常見的。
接下來準(zhǔn)備寫一段代碼,模擬桌面程序中的I/O Pinout功能,列舉出所有可用的外設(shè),放到一個(gè)RecyclerView組件中,最終運(yùn)行的效果圖如下
如同Android程序開發(fā)一樣, Android Things中使用layout來對(duì)屏幕進(jìn)行布局,初始代碼如下
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
傳統(tǒng)的RelativeLayout已被ConstraintLayout取代,新的布局可以有效消除嵌套問題,執(zhí)行效率更高!
將TextView去掉,添加新的RecyclerView來顯示接口列表
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
android:id="@+id/recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
接下來要在java代碼添加功能,通過API來獲取設(shè)備接口,然后添加到RecyclerView中就行了。
public class MainActivity extends Activity {
private RecyclerView mRecyclerView;
class MyHolder extends RecyclerView.ViewHolder {
private TextView mTextView;
public MyHolder(View itemView) {
super(itemView);
mTextView = (TextView) itemView;
}
}
-
- 本文系21ic原創(chuàng),未經(jīng)許可禁止轉(zhuǎn)載!
網(wǎng)友評(píng)論
- 聯(lián)系人:巧克力娃娃
- 郵箱:board@21ic.com
- 我要投稿
-
歡迎入駐,開放投稿
- NRF52810藍(lán)牙數(shù)字耳機(jī)找人定制
預(yù)算:¥30005天前
- 125KW模塊式PCS軟硬件外包開發(fā)
預(yù)算:¥1100000015小時(shí)前
- 12V汽車啟動(dòng)電源項(xiàng)目BMS設(shè)計(jì)
預(yù)算:¥50000023小時(shí)前
- 數(shù)據(jù)可視化軟件 開發(fā)
預(yù)算:¥5000023小時(shí)前
- PLC項(xiàng)目調(diào)試修改
預(yù)算:¥100001天前
- 起動(dòng)電機(jī)控制器開發(fā)
預(yù)算:¥1100001天前