最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

使用ViewPager實現(xiàn)android軟件使用向導功能實現(xiàn)步驟

 更新時間:2013年11月26日 15:48:52   作者:  
現(xiàn)在的大部分android軟件,都是使用說明,就是第一次使用該軟件時,會出現(xiàn)向導,可以左右滑動,然后就進入應用的主界面了,下面我們就實現(xiàn)這個功能



首先需要一個布局文件,是FlameLayout組成的,里面包含了一個ViewPager和一個RelativeLayout,RelativeLayout里面是一個LinearLayout,LinearLayout里面是準備放ImageView,動態(tài)添加。

布局文件如下:

復制代碼 代碼如下:

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

    <android.support.v4.view.ViewPager
        android:id="@+id/guidePages"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center" />

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom">
        <LinearLayout
            android:id="@+id/viewGroup"
            android:layout_alignParentBottom="true"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:gravity="center"
            android:layout_marginBottom="30dip">

        </LinearLayout>
    </RelativeLayout>
</FrameLayout>

另外我們需要4個布局文件,就是向導要顯示的圖片,每個布局文件是一頁,每個布局文件里面都是一個ImageView。如下所示:

布局文件一:

復制代碼 代碼如下:

<?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="vertical" >

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:src="@drawable/feature_guide_0"/>"

</LinearLayout>

布局文件二:

復制代碼 代碼如下:

<?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="vertical" >

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:src="@drawable/feature_guide_1"/>

</LinearLayout>

布局文件三:

復制代碼 代碼如下:

<?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="vertical" >

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:src="@drawable/feature_guide_2"/>"

</LinearLayout>

布局文件四:

復制代碼 代碼如下:

<?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="vertical" >

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:src="@drawable/feature_guide_3"/>"

</LinearLayout>

然后在代碼里面加載這4個布局文件和主布局文件:

Activity代碼:

復制代碼 代碼如下:

package com.alex.helloworld;

import java.util.ArrayList;

import android.app.Activity;
import android.os.Bundle;
import android.os.Parcelable;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.view.Window;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;

public class HelloWord2 extends Activity implements OnPageChangeListener {

    private ArrayList<View> mPageViews;
    private LayoutInflater mInflater;
    private LinearLayout mGroups;
    private FrameLayout mMain;
    private ViewPager mViewPager;
    private ImageView[] mImageViews;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        mInflater = LayoutInflater.from(this);
        mPageViews = new ArrayList<View>();
        mPageViews.add(mInflater.inflate(R.layout.item_0, null));
        mPageViews.add(mInflater.inflate(R.layout.item_1, null));
        mPageViews.add(mInflater.inflate(R.layout.item_2, null));
        mPageViews.add(mInflater.inflate(R.layout.item_3, null));

        mMain = (FrameLayout) mInflater.inflate(R.layout.hello2, null);
        mGroups = (LinearLayout) mMain.findViewById(R.id.viewGroup);
        mViewPager = (ViewPager) mMain.findViewById(R.id.guidePages);
        mImageViews = new ImageView[mPageViews.size()];

        for(int i=0; i<mPageViews.size(); i++) {
            ImageView iv = new ImageView(this);
            iv.setLayoutParams(new LayoutParams(20, 20));
            mImageViews[i] = iv;
            if(i == 0) {
                mImageViews[i].setBackgroundResource(R.drawable.page_indicator_focused);
            } else {
                mImageViews[i].setBackgroundResource(R.drawable.page_indicator);
            }
            mGroups.addView(mImageViews[i]);
        }
        mViewPager.setAdapter(mPageAdapter);
        mViewPager.setOnPageChangeListener(this);
        setContentView(mMain);
    }

    private PagerAdapter mPageAdapter = new PagerAdapter() {

        @Override
        public void startUpdate(View arg0) {

        }

        @Override
        public Parcelable saveState() {
            return null;
        }

        @Override
        public void restoreState(Parcelable arg0, ClassLoader arg1) {

        }

        @Override
        public boolean isViewFromObject(View arg0, Object arg1) {
            return arg0 == arg1;
        }

        @Override
        public Object instantiateItem(View arg0, int arg1) {
            ((ViewPager)arg0).addView(mPageViews.get(arg1));
            return mPageViews.get(arg1);
        }

        @Override
        public int getCount() {
            return mPageViews.size();
        }

        @Override
        public void finishUpdate(View arg0) {

        }

        @Override
        public void destroyItem(View arg0, int arg1, Object arg2) {
            ((ViewPager)arg0).removeView(mPageViews.get(arg1));
        }
    };

    @Override
    public void onPageScrolled(int position, float positionOffset,
            int positionOffsetPixels) {

    }

    @Override
    public void onPageSelected(int position) {
        for(int i=0; i<mPageViews.size(); i++) {
            mImageViews[position].setBackgroundResource(R.drawable.page_indicator_focused);
            if(position != i) {
                mImageViews[i].setBackgroundResource(R.drawable.page_indicator);
            }
        }
    }

    @Override
    public void onPageScrollStateChanged(int state) {

    }
}

首先從LayoutInflater里面加載4個要顯示的布局和主布局文件。

然后把布局文件作為View放到一個ArrayList里面。

然后從主布局里面找到ViewPager和LinearLayout,ViewPager用來裝載4個布局文件,LinearLayout用來裝載4個提示圖標。

然后新建4個ImageView,并設置對應的背景,然后作為View添加到LinearLayout里面去。

然后給ViewPager設置Adapter,設置onPageChangeListener。

Adapter里面要設置getCount,就是頁面的個數,我們這里是4個,就設置4;

同時在instantiateItem里面講對應的頁面add進去,并返回對應的頁面。

在destroyItem的時候講頁面remove掉。

在選擇頁面的方法里面onPageSelected里面設置選中圖標的背景。

相關文章

  • Android開發(fā)之線程通信詳解

    Android開發(fā)之線程通信詳解

    這篇文章主要為大家詳細介紹了Android開發(fā)中線程間通信的相關資料,文中的示例代碼講解詳細,對我們學習Android有一定的幫助,?需要的可以了解一下
    2022-11-11
  • Android游戲開發(fā)學習之引擎用法實例詳解

    Android游戲開發(fā)學習之引擎用法實例詳解

    這篇文章主要介紹了Android游戲開發(fā)學習之引擎用法,較為詳細的分析了Android游戲開發(fā)中所常用的JBox2D引擎功能及相關使用技巧,具有一定參考借鑒價值,需要的朋友可以參考下
    2015-10-10
  • Android 情景模式的設置代碼

    Android 情景模式的設置代碼

    Android 情景模式的設置代碼,需要的朋友可以參考一下
    2013-05-05
  • Android中默認系統(tǒng)的聲音/大小修改和配置詳解

    Android中默認系統(tǒng)的聲音/大小修改和配置詳解

    這篇文章主要給大家介紹了關于Android中默認系統(tǒng)的聲音/大小修改和配置的相關資料,文中通過示例代碼介紹的非常詳細,對各位Android開發(fā)者們具有一定的參考學習價值,需要的朋友們下面來一起看看吧。
    2017-11-11
  • 解析Android開發(fā)優(yōu)化之:從代碼角度進行優(yōu)化的技巧

    解析Android開發(fā)優(yōu)化之:從代碼角度進行優(yōu)化的技巧

    下面我們就從幾個方面來了解Android開發(fā)過程中的代碼優(yōu)化,需要的朋友參考下
    2013-05-05
  • Android利用ViewPager實現(xiàn)帶小圓球的圖片滑動

    Android利用ViewPager實現(xiàn)帶小圓球的圖片滑動

    這篇文章主要為大家詳細介紹了Android利用ViewPager實現(xiàn)帶小圓球的圖片滑動,并且只有第一次安裝app時才出現(xiàn)歡迎界面具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-11-11
  • Android Studio配置國內鏡像源(利用hosts)

    Android Studio配置國內鏡像源(利用hosts)

    這篇文章主要介紹了Android Studio配置國內鏡像源(利用hosts),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2020-11-11
  • Android NDK開發(fā)(C語言基本數據類型)

    Android NDK開發(fā)(C語言基本數據類型)

    這篇文章主要介紹了Android NDK開發(fā)中,C語言基本數據類型,主要以C語言包含的數據類型及基本類型展開相關資料,需要的朋友可以參考一下
    2021-12-12
  • Android SharedPreferences數據存儲詳解

    Android SharedPreferences數據存儲詳解

    SharedPreferences是安卓平臺上一個輕量級的存儲類,用來保存應用的一些常用配置,比如Activity狀態(tài),Activity暫停時,將此activity的狀態(tài)保存到SharedPereferences中;當Activity重載,系統(tǒng)回調方法onSaveInstanceState時,再從SharedPreferences中將值取出
    2022-11-11
  • Android 中 ThreadLocal使用示例

    Android 中 ThreadLocal使用示例

    這篇文章主要介紹了Android 中 ThreadLocal使用示例的相關資料,這里提供示例代碼幫助大家學習理解這部分內容,需要的朋友可以參考下
    2017-09-09

最新評論

洞头县| 都兰县| 察哈| 新竹市| 香港| 潮州市| 鞍山市| 星子县| 濉溪县| 屏南县| 深泽县| 西乡县| 凤冈县| 普安县| 厦门市| 香港 | 南康市| 梧州市| 大余县| 措美县| 汝州市| 偏关县| 若尔盖县| 万载县| 精河县| 闽侯县| 灵寿县| 资兴市| 赫章县| 延庆县| 井冈山市| 湟中县| 福建省| 长白| 洪泽县| 惠来县| 呈贡县| 云南省| 紫阳县| 手游| 北票市|