Android高仿360安全卫士--布局篇(一)

本文介绍了一款模仿360手机卫士的Demo应用,通过自定义ViewPager实现了页面左右滑动功能,并在布局文件中添加了组件点击事件。主要涉及Android开发中的自定义View和ViewPager组件使用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 最近模仿360手机卫士,做了一个Demo。看了一下360的布局文件,发现它是自定义的View,而不是官方提供的基本组件的组合。效果如下图所示:




这个Demo是可以左右滑动的,并且可以在布局文件中添加组件点击事件。主要是利用ViewPager类来实现的。

MainActivity.java

package com.example.viewpapertest;


import java.util.ArrayList;
import java.util.List;
import android.os.Bundle;
import android.os.Parcelable;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Toast;


public class MainActivity extends Activity {


private ViewPager awesomePager;  
private LinearLayout lin1, lin2;  
    private Context cxt;  
    private AwesomePagerAdapter awesomeAdapter;  
    private LayoutInflater mInflater;  
    private List<View> mListViews;  
    boolean result = true;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        cxt = this;  
        
lin1 = (LinearLayout) findViewById(R.id.lin1);
lin2 = (LinearLayout) findViewById(R.id.lin2);

        awesomeAdapter = new AwesomePagerAdapter();  
        awesomePager = (ViewPager) findViewById(R.id.awesomepager);  
        awesomePager.setAdapter(awesomeAdapter);  
          
        mListViews = new ArrayList<View>();  
        mInflater = getLayoutInflater();  
        mListViews.add(mInflater.inflate(R.layout.tab1, null));  
        mListViews.add(mInflater.inflate(R.layout.tab2, null));  
        
       
       }


    private class AwesomePagerAdapter extends PagerAdapter{  
     
        
        public int getCount() {  
            return mListViews.size();  
        }  
  
        /** 
         * Create the page for the given position.  The adapter is responsible 
         * for adding the view to the container given here, although it only 
         * must ensure this is done by the time it returns from 
         * {@link #finishUpdate()}. 
         * 
         * @param container The containing View in which the page will be shown. 
         * @param position The page position to be instantiated. 
         * @return Returns an Object representing the new page.  This does not 
         * need to be a View, but can be some other container of the page. 
         */  
        public Object instantiateItem(View collection, int position) {  
  
              
            ((ViewPager) collection).addView(mListViews.get(position),0);  
            if (position ==0 ) {  
            ImageView download_btn=(ImageView) collection.findViewById(R.id.download_btn);
            download_btn.setOnClickListener(new View.OnClickListener() {  
             
                               public void onClick(View v) {  

/*
                               if (result == true) {
                   lin1.scrollBy(0, 0);
                   lin1.scrollTo(80, 0);
                   lin1.setPadding(0, 30, 0, 30);
                   lin2.setVisibility(View.VISIBLE);
                   result = false;


                   } else {
                   lin1.setPadding(10, 30, 0, 30);
                   lin1.scrollBy(80, 0);
                   lin1.scrollTo(0, 0);
                   lin2.setVisibility(View.GONE);
                   result = true;
                               }  
                               }
                           });  
            */
                       }else{
                       ImageView download_btn=(ImageView) collection.findViewById(R.id.download_btn);
                       download_btn.setOnClickListener(new View.OnClickListener() {  
                        
                                          public void onClick(View v) {  
                                              new AlertDialog.Builder(MainActivity.this)  
                                                      .setTitle("说明")  
                                                      .setMessage("单个页卡内按钮事件测试")  
                                                      .setNegativeButton("确定",  
                                                             new DialogInterface.OnClickListener() {  
                                                                  public void onClick(  
                                                                          DialogInterface dialog,  
                                                                          int which) {  
                                                                 }  
                                                               }).show();  
                                          }  
                                      });  
                       }


            return mListViews.get(position);  
        }  
  
        /** 
         * Remove a page for the given position.  The adapter is responsible 
         * for removing the view from its container, although it only must ensure 
         * this is done by the time it returns from {@link #finishUpdate()}. 
         * 
         * @param container The containing View from which the page will be removed. 
         * @param position The page position to be removed. 
         * @param object The same object that was returned by 
         * {@link #instantiateItem(View, int)}. 
         */  
        public void destroyItem(View collection, int position, Object view) {  
            ((ViewPager) collection).removeView(mListViews.get(position));  
        }  
  
          
          
        public boolean isViewFromObject(View view, Object object) {  
            return view==(object);  
        }  
  
          
        /** 
         * Called when the a change in the shown pages has been completed.  At this 
         * point you must ensure that all of the pages have actually been added or 
         * removed from the container as appropriate. 
         * @param container The containing View which is displaying this adapter's 
         * page views. 
         */  
        public void finishUpdate(View arg0) {}  
          
  
        public void restoreState(Parcelable arg0, ClassLoader arg1) {}  
  
        public Parcelable saveState() {  
            return null;  
        }  
  
        public void startUpdate(View arg0) {}  
          
    }  
      
        
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
}

  main.xml

<RelativeLayout 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.support.v4.view.ViewPager
    android:id="@+id/awesomepager"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
</android.support.v4.view.ViewPager>


</RelativeLayout>

tab.xml

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >


    <LinearLayout
        android:id="@+id/lin1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:baselineAligned="false"
        android:background="@drawable/rootblock_default_bg"
        android:orientation="horizontal"
        android:paddingBottom="30dp"
        android:paddingLeft="10dp"
        android:paddingTop="30dp" >


        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:orientation="vertical" >


            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal" >


                <LinearLayout
                    android:layout_width="108dp"
                    android:layout_height="108dp"
                    android:background="#FF7F24" >
                </LinearLayout>


                <LinearLayout
                    android:layout_width="108dp"
                    android:layout_height="108dp"
                    android:layout_marginLeft="5dp"
                    android:background="#FF7F24" >
                </LinearLayout>
            </LinearLayout>


            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dp"
                android:orientation="horizontal" >


                <LinearLayout
                    android:layout_width="108dp"
                    android:layout_height="108dp"
                    android:background="#3399ff" >
                </LinearLayout>


                <LinearLayout
                    android:layout_width="108dp"
                    android:layout_height="108dp"
                    android:layout_marginLeft="5dp"
                    android:background="#3399ff" >
                </LinearLayout>
            </LinearLayout>


            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dp"
                android:orientation="horizontal" >


                <LinearLayout
                    android:layout_width="108dp"
                    android:layout_height="108dp"
                    android:background="#3399ff" >
                </LinearLayout>


                <LinearLayout
                    android:layout_width="108dp"
                    android:layout_height="108dp"
                    android:layout_marginLeft="5dp"
                    android:background="#3399ff" >
                </LinearLayout>
            </LinearLayout>


            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dp"
                android:orientation="horizontal" >


                <LinearLayout
                    android:layout_width="108dp"
                    android:layout_height="108dp"
                    android:background="#953399ff" >
                </LinearLayout>


                <LinearLayout
                    android:layout_width="108dp"
                    android:layout_height="108dp"
                    android:layout_marginLeft="5dp"
                    android:background="#953399ff" >
                </LinearLayout>
            </LinearLayout>
        </LinearLayout>


        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:orientation="vertical" >


            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="fill_parent" >


                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentBottom="true"
                    android:orientation="vertical" >


                    <ImageView
                        android:id="@+id/download_btn"
                        android:layout_width="36dp"
                        android:layout_height="36dp"
                        android:src="@drawable/rootblock_icon_download_bg" />


                    <ImageView
                        android:id="@+id/delete_btn"
                        android:layout_width="36dp"
                        android:layout_height="36dp"
                        android:layout_marginTop="20dp"
                        android:src="@drawable/rootblock_icon_clear_bg" />


                    <ImageView
                        android:id="@+id/set_btn"
                        android:layout_width="36dp"
                        android:layout_height="36dp"
                        android:layout_marginTop="20dp"
                        android:src="@drawable/rootblock_icon_set_bg" />


                    <ImageView
                        android:id="@+id/etra_btn"
                        android:layout_width="36dp"
                        android:layout_height="36dp"
                        android:layout_marginTop="20dp"
                        android:src="@drawable/rootblock_icon_add_bg" />
                </LinearLayout>
            </RelativeLayout>
        </LinearLayout>
    </LinearLayout>


    <LinearLayout
        android:id="@+id/lin2"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_gravity="right"
        android:background="#000000"
        android:orientation="vertical"
        android:visibility="gone" >


        <TextView
            android:layout_width="80dp"
            android:layout_height="fill_parent"
            android:text="dddddddddddd" />
    </LinearLayout>


</FrameLayout>

  关于Viewpager的用法大家可以去看一下资料,在此不再详述。这个tab.xml就是用来切换的布局,也就是左右滑动的布局文件。我们在这里用来两个切换布局,可以根据自己的需求动态增删。但是,仔细看官方的程序我们发现,它的背景是不变的。就这需要使用其他的方法来实现,也就是自定义View,下一节将讲述如何自定义View来实现。

需要源码的朋友可以留一下你的邮箱。

项目名称:[精仿]360安全卫士-10.30更新(CSkin Demo) 界面库版本号:10.30 最新版本 下载内容: 精仿360安全卫士源码份, 可引用至工具箱最新版CSkin.dll份 实现功能: 1.发光标题。 2.直角边框和阴影。 3.360安全卫士主界面模仿。 4.多系统支持,不需要win8系统,即可实现win8风格的360。 5.自定义控件的美化使用。 界面库更新文档: CC2013-10.30 1.由于SkinForm名字太多人使用,界面库命名正式改为CSkin.dll,官网www.cskin.net。 2.SkinTabControl标签中添加菜单箭头,可点击展开菜单。 3.SkinTabControl添加标签关闭按钮。 4.修复部分中文乱码问题。 5.优化好友列表右键菜单。 6.将窗体自定义系统按钮改为集合模式,可添加无数个自定义系统按钮。自定义系统按钮事件中可以 e.参数 来判断。 7.增加360安全卫士-DEMO案例。 8.增加SkinAnimatorImg控件,用于支持位图动画的播放。如360的动态logo。 9.各种细节BUG优化。 CC2013-10.11 1.添加SkinTabControlEx,加入更加自定义的美化属性和动画效果。 2.添加SkinAnimator,通用动画控件。 3.添加Html编辑器控件 4.修复SkinButton图标和文本相对位置的BUG CC2013-9.26 1.优化好友列表CPU占用 2.好友列表加入好友登录平台属性:安卓 苹果 WEBQQ PC 3.优化标题绘制模式,新添标题绘制模式属性。 4.新添标题偏移度属性。 5.加入圆形进度条控件:ProgressIndicator。 CC2013-9.5.2 1.优化截图控件,截图工具栏加入新功能。 2.解决个人信息卡和天气窗体显示后不会消失的问题。 3.各种细节BUG优化。 CC2013-9.5.1 1.解决贴边左右隐藏的BUG。 2.解决窗体点击事件不能触发的问题。 3.优化SkinButton继承父容器背景色的代码。 4.解决SkinButton异常错误。 CC2013-9.3 1.好友列表右键菜单没反应问题。 2.新增美化控件SkinDatagridview。 3.密码软件盘回删不了文字问题。 4.双击窗体最大化,最大化后再双击恢复原大小,(win7)。 5.部分细节调优。 小编:下载不要分,DEMO教你如何熟练使用CSkin界面库美化自己的窗体。 友情链接: http://bbs.youkuaiyun.com/topics/390510544 (仿QQ2013局域通讯) http://download.youkuaiyun.com/detail/lyx_520/5710799 (C#实现Win8窗体)
package com.qihoo360.mobilesafe.provider; import android.content.ContentProvider; import android.content.ContentResolver; import android.content.ContentUris; import android.content.ContentValues; import android.content.Context; import android.content.UriMatcher; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteException; import android.database.sqlite.SQLiteQueryBuilder; import android.net.Uri; import android.os.ParcelFileDescriptor; import android.text.TextUtils; import bl; import c; import d; import e; import f; import g; import h; import i; import j; import java.io.File; import java.util.HashMap; import java.util.List; import java.util.Map; import k; import l; import m; import n; import o; import p; import q; import r; import s; import t; public class SafeGuardProvider extends ContentProvider { public static bl a; private static HashMap b; private static HashMap c; private static HashMap d; private static HashMap e; private static HashMap f; private static HashMap g; private static HashMap h; private static HashMap i; private static HashMap j; private static HashMap k; private static HashMap l; private static HashMap m; private static HashMap n; private static HashMap o; private static HashMap p; private static HashMap q; private static HashMap r; private static HashMap s; private static final UriMatcher t; static { UriMatcher localUriMatcher = new UriMatcher(-1); t = localUriMatcher; localUriMatcher.addURI("com.qihoo360.mobilesafeguard", "blacklist", 1); t.addURI("com.qihoo360.mobilesafeguard", "blacklist/#", 2); t.addURI("com.qihoo360.mobilesafeguard", "msg_history", 3); t.addURI("com.qihoo360.mobilesafeguard", "msg_history/#", 4); t.addURI("com.qihoo360.mobilesafeguard", "call_history", 5); t.addURI("com.qihoo360.mobilesafeguard", "call_history/#", 6); t.addURI("com.qihoo360.mobilesafeguard", "whitelist", 7); t.addURI("com.qihoo360.mobilesafeguard", "whitelist/#", 8); t.addURI("com.qihoo360.mobilesafeguard", "private_in_call", 9); t.addURI("com.qihoo360.mobilesafeguard", "private_in_call/#", 10); t.addURI("com.qihoo360.mobilesafeguard", "private_out_call", 11); t.addURI("com.qihoo360.mobilesafeguard", "private_out_call/#", 12); t.addURI("com.qihoo360.mobilesafeguard", "private_in_mms", 13); t.addURI("com.qihoo360.mobilesafeguard", "private_in_mms/#", 14); t.addURI("com.qihoo360.mobilesafeguard", "private_out_mms", 15); t.addURI("com.qihoo360.mobilesafeguard", "private_out_mms/#", 16); t.addURI("com.qihoo360.mobilesafeguard", "private_mms", 19); t.addURI("com.qihoo360.mobilesafeguard", "private_mms/#", 20); t.addURI("com.qihoo360.mobilesafeguard", "privatelist", 17); t.addURI("com.qihoo360.mobilesafeguard", "privatelist/#", 18); t.addURI("com.qihoo360.mobilesafeguard", "smartwhite", 21); t.addURI("com.qihoo360.mobilesafeguard", "smartwhite/#", 22); t.addURI("com.qihoo360.mobilesafeguard", "private_call_in", 23); t.addURI("com.qihoo360.mobilesafeguard", "private_call_in/#", 24); t.addURI("com.qihoo360.mobilesafeguard", "private_call_out", 25); t.addURI("com.qihoo360.mobilesafeguard", "private_call_out/#", 26); t.addURI("com.qihoo360.mobilesafeguard", "private_mms_in", 27); t.addURI("com.qihoo360.mobilesafeguard", "private_mms_in/#", 28); t.addURI("com.qihoo360.mobilesafeguard", "private_mms_out", 29); t.addURI("com.qihoo360.mobilesafeguard", "private_mms_out/#", 30); t.addURI("com.qihoo360.mobilesafeguard", "private_message", 33); t.addURI("com.qihoo360.mobilesafeguard", "private_message/#", 34); t.addURI("com.qihoo360.mobilesafeguard", "privatecontacts", 31); t.addURI("com.qihoo360.mobilesafeguard", "privatecontacts/#", 32); t.addURI("com.qihoo360.mobilesafeguard", "ipnouselist", 35); t.addURI("com.qihoo360.mobilesafeguard", "ipnouselist/#", 36); HashMap localHashMap1 = new HashMap(); b = localHashMap1; localHashMap1.put("_id", "_id"); b.put("contact_name", "contact_name"); b.put("phone_number", "phone_number"); b.put("blocked_type", "blocked_type"); HashMap localHashMap2 = new HashMap(); c = localHashMap2; localHashMap2.put("_id", "_id"); c.put("address", "address"); c.put("date", "date"); c.put("subject", "subject"); c.put("body", "body"); c.put("read", "read"); c.put("type", "type"); HashMap localHashMap3 = new HashMap(); d = localHashMap3; localHashMap3.put("_id", "_id"); d.put("address", "address"); d.put("date", "date"); d.put("read", "read"); d.put("block_type", "block_type"); HashMap localHashMap4 = new HashMap(); e = localHashMap4; localHashMap4.put("_id", "_id"); e.put("contact_name", "contact_name"); e.put("phone_number", "phone_number"); HashMap localHashMap5 = new HashMap(); f = localHashMap5; localHashMap5.put("_id", "_id"); f.put("name", "name"); f.put("number", "number"); f.put("date", "date"); f.put("blocked_type", "blocked_type"); HashMap localHashMap6 = new HashMap(); g = localHashMap6; localHashMap6.put("_id", "_id"); g.put("name", "name"); g.put("number", "number"); g.put("date", "date"); HashMap localHashMap7 = new HashMap(); h = localHashMap7; localHashMap7.put("_id", "_id"); h.put("name", "name"); h.put("address", "address"); h.put("date", "date"); h.put("subject", "subject"); h.put("body", "body"); HashMap localHashMap8 = new HashMap(); i = localHashMap8; localHashMap8.put("_id", "_id"); i.put("name", "name"); i.put("address", "address"); i.put("date", "date"); i.put("subject", "subject"); i.put("body", "body"); HashMap localHashMap9 = new HashMap(); j = localHashMap9; localHashMap9.put("_id", "_id"); j.put("name", "name"); j.put("address", "address"); j.put("date", "date"); j.put("subject", "subject"); j.put("body", "body"); j.put("mms_recv_type", "mms_recv_type"); j.put("mms_type", "mms_type"); j.put("read", "read"); HashMap localHashMap10 = new HashMap(); k = localHashMap10; localHashMap10.put("_id", "_id"); k.put("contact_name", "contact_name"); k.put("phone_number", "phone_number"); k.put("blocked_type", "blocked_type"); HashMap localHashMap11 = new HashMap(); l = localHashMap11; localHashMap11.put("_id", "_id"); l.put("p_n", "p_n"); l.put("s_a_t", "s_a_t"); HashMap localHashMap12 = new HashMap(); m = localHashMap12; localHashMap12.put("_id", "_id"); m.put("name", "name"); m.put("pre_number", "pre_number"); m.put("number", "number"); m.put("date", "date"); m.put("blocked_type", "blocked_type"); HashMap localHashMap13 = new HashMap(); n = localHashMap13; localHashMap13.put("_id", "_id"); n.put("name", "name"); n.put("pre_number", "pre_number"); n.put("number", "number"); n.put("date", "date"); HashMap localHashMap14 = new HashMap(); o = localHashMap14; localHashMap14.put("_id", "_id"); o.put("name", "name"); o.put("pre_address", "pre_address"); o.put("address", "address"); o.put("date", "date"); o.put("subject", "subject"); o.put("body", "body"); HashMap localHashMap15 = new HashMap(); p = localHashMap15; localHashMap15.put("_id", "_id"); p.put("name", "name"); p.put("pre_address", "pre_address"); p.put("address", "address"); p.put("date", "date"); p.put("subject", "subject"); p.put("body", "body"); HashMap localHashMap16 = new HashMap(); q = localHashMap16; localHashMap16.put("_id", "_id"); q.put("name", "name"); q.put("pre_address", "pre_address"); q.put("address", "address"); q.put("date", "date"); q.put("subject", "subject"); q.put("body", "body"); q.put("mms_recv_type", "mms_recv_type"); q.put("mms_type", "mms_type"); q.put("read", "read"); HashMap localHashMap17 = new HashMap(); r = localHashMap17; localHashMap17.put("_id", "_id"); r.put("contact_name", "contact_name"); r.put("pre_number", "pre_number"); r.put("phone_number", "phone_number"); r.put("blocked_type", "blocked_type"); HashMap localHashMap18 = new HashMap(); s = localHashMap18; localHashMap18.put("_id", "_id"); s.put("contact_name", "contact_name"); s.put("phone_number", "phone_number"); } public int delete(Uri paramUri, String paramString, String[] paramArrayOfString) { Object localObject1 = " AND ("; String str1 = ""; ContentResolver localContentResolver = null; SQLiteDatabase localSQLiteDatabase; try { localSQLiteDatabase = a.getWritableDatabase(); localObject1 = t.match(paramUri); switch (localObject1) { default: String str2 = "Unknown URI " + paramUri; localObject1 = new IllegalArgumentException(str2); label225: throw ((Throwable)localObject1); case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 9: case 10: case 11: case 12: case 13: case 14: case 15: case 16: case 19: case 20: case 17: case 18: case 21: case 22: case 23: case 24: case 25: case 26: case 27: case 28: case 29: case 30: case 33: case 34: case 31: case 32: case 35: case 36: } }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值