Android窗口小部件基礎編寫代碼實例
實現窗口小部件,訪問手機儲存卡指定目錄中的圖片文件,然后隨機選擇一張在窗口的小部件中顯示。圖片路徑使用List存儲,適合初級Android學習者參考。本系統無服務,不能保證進程長存。
新建一個空的布局項目,然后新建一個Widget,如圖所示:
在新建的xml和java實現類中進行編寫即可。
picture_widget.xml文件如下:
<RelativeLayout xmlns:android='http://schemas.android.com/apk/res/android' android:layout_width='match_parent' android:layout_height='match_parent' android:padding='@dimen/widget_margin'> <ImageView android: android:layout_width='match_parent' android:layout_height='match_parent' android:src='http://www.intensediesel.com/bcjs/@drawable/zhizhuxia' /> <TextView android: android:layout_width='wrap_content' android:layout_height='wrap_content' android:text='' android:textSize='10dp' android:gravity='right|bottom' android:layout_marginRight='2dp' android:layout_marginBottom='2dp'/></RelativeLayout>
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。
相關文章: