开发学院手机开发Android 开发 Android高仿360安全卫士布局 阅读


 2012-10-18 12:01:42 来源:WEB开发网   
核心提示: 最近模仿360手机卫士,做了一个Demo,Android高仿360安全卫士布局,看了一下360的布局文件,发现它是自定义的View,而不是官方提供的基本组件的组合,效果如下图所示: 这个Demo是可以左右滑动的


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;
    public void onCreate(Bundle savedInstanceState) {
        cxt = this;  
lin1 = (LinearLayout) findViewById(R.id.lin1);
lin2 = (LinearLayout) findViewById(R.id.lin2);

        awesomeAdapter = new AwesomePagerAdapter();  
        awesomePager = (ViewPager) findViewById(R.id.awesomepager);  
        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) {  

1 2 3  下一页

Tags:Android 高仿 安全

编辑录入:爽爽 [复制链接] [打 印]