华域联盟 Andriod Android窗口小部件基础编写代码实例

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:id="@+id/picture_widget"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:src="@drawable/zhizhuxia" />
  <TextView
    android:id="@+id/change_picture"
    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>

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持华域联盟。

本文由 华域联盟 原创撰写:华域联盟 » Android窗口小部件基础编写代码实例

转载请保留出处和原文链接:https://www.cnhackhy.com/108913.htm

本文来自网络,不代表华域联盟立场,转载请注明出处。

作者: sterben

Android Studio配置国内镜像源(利用hosts)

Android实现网易云音乐的旋转专辑View

发表回复

联系我们

联系我们

2551209778

在线咨询: QQ交谈

邮箱: [email protected]

工作时间:周一至周五,9:00-17:30,节假日休息

关注微信
微信扫一扫关注我们

微信扫一扫关注我们