93杀毒的UI实现

来源:互联网 发布:linux vi怎么保存退出 编辑:程序博客网 时间:2024/05/29 20:02

实现后的效果如图:


布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:background="#f2f0eb"    android:orientation="vertical" >    <TextView        android:id="@+id/title"        android:layout_width="match_parent"        android:layout_height="50dp"        android:background="#2FD5B9"        android:gravity="center"        android:text="手机杀毒"        android:textColor="#ffffff"        android:textSize="20sp" />    <LinearLayout        android:layout_width="fill_parent"        android:layout_height="80dip"        android:orientation="horizontal" >        <FrameLayout            android:layout_width="80dip"            android:layout_height="80dip" >            <ImageView                android:layout_width="80dip"                android:layout_height="80dip"                android:src="@drawable/ic_scanner_malware" />            <ImageView                android:id="@+id/iv_scan"                android:layout_width="80dip"                android:layout_height="80dip"                android:src="@drawable/act_scanning_03" />        </FrameLayout>        <LinearLayout            android:layout_width="fill_parent"            android:layout_height="80dip"            android:gravity="center"            android:orientation="vertical" >            <TextView                android:id="@+id/tv_scan_status"                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:singleLine="true"                android:text="扫描状态"                android:textColor="#000000"                android:textSize="18sp" />            <ProgressBar                android:id="@+id/progressBar1"                style="?android:attr/progressBarStyleHorizontal"                android:layout_width="fill_parent"                android:layout_height="wrap_content"                android:layout_marginLeft="10dip"                android:layout_marginRight="10dip"                android:progressDrawable="@drawable/progress_horizontal" />        </LinearLayout>    </LinearLayout>    <ScrollView        android:layout_width="fill_parent"        android:layout_height="fill_parent" >        <LinearLayout            android:id="@+id/ll_container"            android:layout_width="fill_parent"            android:layout_height="fill_parent"            android:orientation="vertical" >        </LinearLayout>    </ScrollView></LinearLayout>

包含下面的几部分内容:

一是动画,而是扫描状态的文字,三是扫描的进度条,四是下面扫描到的包名,可能文本很多,使用了ScrollView包裹了。

关心的是进度条的实现:

其一是:

style="?android:attr/progressBarStyleHorizontal"

指定了其样式;

其二是:

android:progressDrawable="@drawable/progress_horizontal"
这个对应的drawable文件为:

<?xml version="1.0" encoding="utf-8"?><!-- Copyright (C) 2008 The Android Open Source Project     Licensed under the Apache License, Version 2.0 (the "License");     you may not use this file except in compliance with the License.     You may obtain a copy of the License at          http://www.apache.org/licenses/LICENSE-2.0     Unless required by applicable law or agreed to in writing, software     distributed under the License is distributed on an "AS IS" BASIS,     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.     See the License for the specific language governing permissions and     limitations under the License.--><layer-list xmlns:android="http://schemas.android.com/apk/res/android">        <item android:id="@android:id/background" android:drawable="@drawable/security_progress_bg">         </item>        <item android:id="@android:id/secondaryProgress" android:drawable="@drawable/security_progress">          </item>        <item android:id="@android:id/progress" android:drawable="@drawable/security_progress">    </item>    </layer-list>

注意这里的结点是:layer-list(将多个图层堆叠到一块)

类文件指定动画:

package com.ustc.mobilemanager;import android.app.Activity;import android.os.Bundle;import android.view.Window;import android.view.animation.Animation;import android.view.animation.RotateAnimation;import android.widget.ImageView;import android.widget.ProgressBar;public class AntiVirusActivity extends Activity {private ImageView iv_scan;private ProgressBar progressBar1;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);requestWindowFeature(Window.FEATURE_NO_TITLE);setContentView(R.layout.activity_anti_virus);iv_scan = (ImageView) findViewById(R.id.iv_scan);progressBar1 = (ProgressBar) findViewById(R.id.progressBar1);progressBar1.setMax(100);new Thread(new Runnable() {@Overridepublic void run() {for (int i = 0; i < 100; i++) {try {Thread.sleep(100);progressBar1.setProgress(i);} catch (Exception e) {e.printStackTrace();}}}}).start();RotateAnimation ra = new RotateAnimation(0, 360,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);ra.setDuration(1000);ra.setRepeatCount(Animation.INFINITE);iv_scan.setAnimation(ra);}}









0 0
原创粉丝点击