Android-PhoneGuardian之启动界面

来源:互联网 发布:hadoop tensorflow 编辑:程序博客网 时间:2024/06/05 16:09

今天我们看下一个简单的app启动界面,界面十分简单,只有一张图片和一个进度条。直接上图了。

创建一个新的工程,然后修改启动Activity为SplashActivity,创建好的工程如下



由于只是做简单的页面布局,不涉及代码实现,所以我们直接看下这个启动界面的布局。

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    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"    android:gravity="center"    android:orientation="vertical"    tools:context="com.easygoings.phoneguardian.SplashActivity">    <ImageView        android:id="@+id/iv_bg"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_gravity="center"        android:layout_marginLeft="30dp"        android:layout_marginRight="30dp"        android:src="@drawable/logo"></ImageView>    <ProgressBar        android:id="@+id/pb_progress"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:indeterminateDrawable="@drawable/pb_progress"/></LinearLayout>

布局很简单,是一个线性布局框架,然后里面有一个ImageView来显示logo图片,另外有一个ProgressBar来显示加载进度条。

代码很容易看懂,值得说的是可能作为刚接触android来说,对其中的属性比较陌生,望文生义,这里就只说一下android:indeterminateDrawable 这个属性设置绘制不显示进度的进度条的Drawable对象。

在资源文件里创建pb_progress.xml来定制我们想要的样子。

<?xml version="1.0" encoding="utf-8"?><animated-rotate xmlns:android="http://schemas.android.com/apk/res/android"    android:pivotX="50%" android:pivotY="50%"    android:fromDegrees="0"    android:toDegrees="360">    <shape        android:shape="ring"        android:innerRadiusRatio="3"        android:thicknessRatio="8"        android:useLevel="false">        <gradient            android:type="sweep"            android:useLevel="false"            android:startColor="#6BD3FF"            android:centerColor="#FF7121"            android:centerY="0.50"            android:endColor="#FFFF00" />    </shape></animated-rotate>

看名字大概就可以知道这是动画旋转相关的。让我们看下其中的参数:

android:fromDegrees 起始的角度度数 android:toDegrees 结束的角度度数,负数表示逆时针,正数表示顺时针。如10圈则比android:fromDegrees大3600即可 android:pivotX 旋转中心的X坐标 浮点数或是百分比。浮点数表示相对于Object的左边缘,如5; 百分比表示相对于Object的左边缘,如5%; 另一种百分比表示相对于父容器的左边缘,如5%p; 一般设置为50%表示在Object中心 android:pivotY 旋转中心的Y坐标 浮点数或是百分比。浮点数表示相对于Object的上边缘,如5; 百分比表示相对于Object的上边缘,如5%; 另一种百分比表示相对于父容器的上边缘,如5%p; 一般设置为50%表示在Object中心 android:duration 表示从android:fromDegrees转动到android:toDegrees所花费的时间,单位为毫秒。可以用来计算速度。 

shape用来定义需要显示的形状,

gradient: 设置形状的渐变颜色,可以是线性渐变、辐射渐变、扫描性渐变

  • android:type 渐变的类型
    • linear 线性渐变,默认的渐变类型
    • radial 放射渐变,设置该项时,android:gradientRadius也必须设置
    • sweep 扫描性渐变
  • android:startColor 渐变开始的颜色
  • android:endColor 渐变结束的颜色
  • android:centerColor 渐变中间的颜色
  • android:angle 渐变的角度,线性渐变时才有效,必须是45的倍数,0表示从左到右,90表示从下到上
  • android:centerX 渐变中心的相对X坐标,放射渐变时才有效,在0.0到1.0之间,默认为0.5,表示在正中间
  • android:centerY 渐变中心的相对X坐标,放射渐变时才有效,在0.0到1.0之间,默认为0.5,表示在正中间
  • android:gradientRadius 渐变的半径,只有渐变类型为radial时才使用
  • android:useLevel 如果为true,则可在LevelListDrawable中使用

原创粉丝点击