Android窗口部件 Android窗口小部件基础编写代码实例

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

Android窗口部件 Android窗口小部件基础编写代码实例

  2021-03-15 我要评论
想了解Android窗口小部件基础编写代码实例的相关内容吗,在本文为您仔细讲解Android窗口部件的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点: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>

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们