欢迎来到代码驿站!

Android代码

当前位置:首页 > 移动开发 > Android代码

Android中自定义加载样式图片的具体实现

时间:2021-04-27 09:10:16|栏目:Android代码|点击:
先让大家看看效果图吧,相信很多Android初学者都想知道这中效果是怎么实现的,来上图:

想实现上面这张图中的自定义加载样式,其实很简单,首先我们需要的布局组件有ProcessBar和TextView,下面是布局文件的代码(只是加载的页面的布局):
复制代码 代码如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:gravity="center">

<ProgressBar
android:id="@+id/progressBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/process_bar_style"/>

<TextView
android:id="@+id/processhint"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="@string/prohint"
android:textSize="18sp" />

</LinearLayout>

因为这个页面的使用平率很高,所以我们把它单独独立出来作为一个XML文件,在Android中如果要在布局文件中引入其他布局文件时,方法其实和JSP编程中的Include十分相似哈,具体的格式如下:<include android:id="@+id/layout_process" layout="@layout/processbar" />

下面我们就来说说要怎么实现旋转进程的实现,由于自带的加载样式不好看,我们就需要自定义样式,这时候需要一张png图片,即旋转的进度条。

接下来我们需要定义style文件。process_style.xml(定义在values文件夹下)
复制代码 代码如下:

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="process_bar_style">
<item name="android:indeterminateDrawable">@drawable/processstyle</item>
</style>
</resources>

定义完style文件后,当然还没实现上面的效果,当然我们还要的就是让图片动起来,那么我们就需要自定义的属性动画哈,process.xml,在drawable文件夹下定义
复制代码 代码如下:

<?xml version="1.0" encoding="utf-8"?>

<animated-rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/process"
android:pivotX="50%"
android:pivotY="50%"
/>

关键的就是这个代码,可以实现图片的自动旋转。

那么大家可以尝试下了哈,自己也能做加载的设计者

上一篇:Android编程自定义AlertDialog样式的方法详解

栏    目:Android代码

下一篇:RecyclerView中使用CheckBox出现勾选混乱的解决方法

本文标题:Android中自定义加载样式图片的具体实现

本文地址:http://www.codeinn.net/misctech/110020.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有