android 左右翻页

布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/color_app_bgk" >

<RelativeLayout
        android:id="@+id/header_homeActivity"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_alignParentTop="true"
        android:background="@drawable/common_titlebar" >

<ImageView
            android:id="@+id/icon_app"
            android:layout_width="32dp"
            android:layout_height="32dp"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:layout_marginLeft="10dp"
            android:background="@drawable/ic_launcher"
            android:contentDescription="@string/app_name" />

<ImageView
            android:id="@+id/icon_phone"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:layout_marginRight="10dp"
            android:contentDescription="@string/app_name"
            android:paddingBottom="16dp"
            android:paddingLeft="24dp"
            android:paddingRight="8dp"
            android:paddingTop="16dp"
            android:src="@drawable/icon_phone" />

<TextView
            android:id="@+id/text_app"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_margin="2dp"
            android:layout_toRightOf="@+id/icon_app"
            android:text="@string/app_name"
            android:textColor="@color/color_white"
            android:textSize="@dimen/font_large" />
    </RelativeLayout>

<RadioGroup
        android:id="@+id/navi_switcher"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/header_homeActivity"
        android:checkedButton="@+id/navi_switcher_item_blogPage"
        android:gravity="center_vertical"
        android:orientation="horizontal" >

<RadioButton
            android:id="@+id/navi_switcher_item_blogPage"
            style="@style/radio_btn_style"
            android:text="@string/main_blogPage" />

<RadioButton
            android:id="@+id/navi_switcher_item_framePage"
            style="@style/radio_btn_style"
            android:text="@string/main_framePage" />

<RadioButton
            android:id="@+id/navi_switcher_item_worksPage"
            style="@style/radio_btn_style"
            android:text="@string/main_worksPage" />

<RadioButton
            android:id="@+id/navi_switcher_item_servePage"
            style="@style/radio_btn_style"
            android:text="@string/main_servePage" />

<RadioButton
            android:id="@+id/navi_switcher_item_aboutPage"
            style="@style/radio_btn_style"
            android:text="@string/main_aboutPage" />
    </RadioGroup>

<android.support.v4.view.ViewPager
        android:id="@+id/navi_view_pager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/navi_switcher"
        android:padding="0dip" >
    </android.support.v4.view.ViewPager>

</RelativeLayout>

Activity:

package lcl.android.ui;

import lcl.android.R;
import lcl.android.core.AppContext;
import lcl.android.core.UpdateManager;
import lcl.android.mail.MailHelper;
import lcl.android.sms.SmsHelper;
import lcl.android.utility.LogUtils;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.KeyEvent;
import android.view.View;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.Toast;

/**
* 应用程序首页
*/
public class Main extends FragmentActivity{
    private AppContext appContext;// 全局Context

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

setContentViews();

getViews();
    }

private void setContentViews() {
        setContentView(R.layout.main);

appContext = (AppContext) getApplication();
    }

private RadioGroup mSwitcher;
    private ViewPager mSearchVp;

private void getViews() {
        mSwitcher = (RadioGroup) findViewById(R.id.navi_switcher);
        mSwitcher.setOnCheckedChangeListener(mCheckedChgLitener);
        mSearchVp = (ViewPager) findViewById(R.id.navi_view_pager);
        mSearchVp.setAdapter(new FrameworkList(getSupportFragmentManager()));
        mSearchVp.setOnPageChangeListener(mPageChgListener);
        View view = this.findViewById(R.id.icon_phone);
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // 打电话
                Intent intent = new Intent(Intent.ACTION_CALL, Uri
                        .parse("tel:13026209315"));
                startActivity(intent);
            }
        });
    }

private final int CB_INDEX_blog = 0;
    private final int CB_INDEX_frame = 1;
    private final int CB_INDEX_work = 2;
    private final int CB_INDEX_serve = 3;
    private final int CB_INDEX_about = 4;

private OnCheckedChangeListener mCheckedChgLitener = new OnCheckedChangeListener() {

@Override
        public void onCheckedChanged(RadioGroup arg0, int checkedId) {

int cur = CB_INDEX_blog;
            switch (checkedId) {
            case R.id.navi_switcher_item_blogPage:
                cur = CB_INDEX_blog;
                break;
            case R.id.navi_switcher_item_framePage:
                cur = CB_INDEX_frame;
                break;
            case R.id.navi_switcher_item_worksPage:
                cur = CB_INDEX_work;
                break;
            case R.id.navi_switcher_item_servePage:
                cur = CB_INDEX_serve;
                break;
            case R.id.navi_switcher_item_aboutPage:
                cur = CB_INDEX_about;
                break;
            }
            if (mSearchVp.getCurrentItem() != cur) {
                mSearchVp.setCurrentItem(cur);
            }
        }
    };
    private OnPageChangeListener mPageChgListener = new OnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            int vpItem = mSearchVp.getCurrentItem();
            switch (vpItem) {
            case CB_INDEX_blog:
                mSwitcher.check(R.id.navi_switcher_item_blogPage);
                break;
            case CB_INDEX_frame:
                mSwitcher.check(R.id.navi_switcher_item_framePage);
                break;
            case CB_INDEX_work:
                mSwitcher.check(R.id.navi_switcher_item_worksPage);
                break;
            case CB_INDEX_serve:
                mSwitcher.check(R.id.navi_switcher_item_servePage);
                break;
            case CB_INDEX_about:
                mSwitcher.check(R.id.navi_switcher_item_aboutPage);
                break;
            }
        }

@Override
        public void onPageScrolled(int arg0, float arg1, int arg2) {
            // TODO Auto-generated method stub

}

@Override
        public void onPageScrollStateChanged(int arg0) {
            // TODO Auto-generated method stub

}
    };

private void checkAppUpdate() {
        // 网络连接判断
        if (appContext.isNetworkConnected()) {
            // 检查新版本
            if (appContext.isCheckUp()) {
                UpdateManager.getUpdateManager().checkAppUpdate(this, false);
                LogUtils.Info("Main checkAppUpdate 检查新版本....");
            }
        }
    }

private long exitTime = 0;

@Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK
                && event.getAction() == KeyEvent.ACTION_DOWN) {
            if ((System.currentTimeMillis() - exitTime) > 2000) {
                Toast.makeText(getApplicationContext(), "再按一次退出程序",
                        Toast.LENGTH_SHORT).show();
                exitTime = System.currentTimeMillis();
            } else {
                finish();
                System.exit(0);
            }
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

@Override
    protected void onResume() {
        // TODO 自动生成的方法存根
        super.onResume();
    }
}

FrameworkList:

package lcl.android.ui;

import java.util.ArrayList;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

public class FrameworkList extends FragmentPagerAdapter {

private ArrayList<Fragment> mFragments;

public FrameworkList(FragmentManager fm) {
        super(fm);
        mFragments = new ArrayList<Fragment>();
        mFragments.add(new Blog());
        mFragments.add(new Framework());
        mFragments.add(new Works());
        mFragments.add(new Serve());
        mFragments.add(new About());
    }

@Override
    public Fragment getItem(int position) {
        return mFragments.get(position);
    }

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

时间: 2024-11-06 07:27:46

android 左右翻页的相关文章

Android水平翻页列表,类似水平GridVIew

Android水平翻页列表,类似于水平方向的GridView,行列自定义,但要翻页切换,考虑加载性能,当Item数据很多时加载和翻页要流畅,翻页时要有动画效果,效果图如下: 实现方式: 1:翻页可用ViewPager来做,每页内多行排列Item,考虑到翻页切换数据和加载的速度不能嵌套GridView,直接使用View来显示. 2:缓存被ViewPager销毁的View,以此来提高当数据量很大时的系统资源消耗问题. 代码实现如下: 1:编写一个PagerAdapter类,用来给ViewPager适

android开发教程:android手势翻页效果

听麦子学院android开发老师说要实现手势翻页效果,主要用到ViewFlipper和GestureDetector.  ViewFlipper变化当前显示内容,GestureDetector监听手势.  用于多页的展示非常酷.  现在我就给大家简单说明下,  首先创建工程:TestFlip,创建主Activity:TestFlip.  在res/layout/main.xml中添加flipper信息,如下:  Java代码   1. <?xml version="1.0" en

Android书籍翻页效果需要用到的文件

模仿此效果,只需要 导入一下文件即可 :BookActivity.java,BookPageFactory.java,PageWidget.java package com.andorid.shu.love; import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.List; import android.app.Activity; import android.c

Qt仿Android带特效的数字时钟源码分析(滑动,翻页,旋转效果)

这个数字时钟的源码可以在Qt Demo中找到,风格是仿Android的,不过该Demo中含有三种动画效果(鉴于本人未曾用过Android的系统,因此不知道Android的数字时钟是否也含有这三种效果),其分别为滑动.翻页和旋转. 由于本人的Qt Creator输入中文后显示的都是乱码,因而在此只能使用英文进行注释,后期如果有时间再进行中文的相关整理.可能有些地方理解并不是很正确.希望大家多多指正! 以下为源码: [cpp] view plaincopy #include <QtCore> #i

android viewpager 图片翻页例子

使用ViewPager这个类可以轻松实现多个页面的滑动功能 viewpager默认在工具界面上是找不到的,需求添加android-support-v4.jar包: 如果没有找到,需要打开Android SDK Manager在Extras中进行下载,最后记得引入工程中并build path. (不过,我把代码直接COPY到.XML好像就会自动添加了) 例子说明:item01..item08是要翻页的图片,page_indicator_focused,page_indicator_unfocuse

android ViewPager左右滑动翻页,并可以删除page

首先新建一个Activity,继承FragmentActivity. 初始化一个Fragment的List集合,用于像FragmentStatePagerAdapter填充数据,而ViewPager由FragmentStatePagerAdapter的实例进行初始化.和ListView一样,Fragment的List集合的数据变了,就通知FragmentStatePagerAdapter进行界面刷新. ArrayList<Fragment> fragments =new ArrayList&l

Android自己定义控件实战——仿多看阅读平移翻页

转载请声明出处http://blog.csdn.net/zhongkejingwang/article/details/38728119 之前自己做的一个APP须要用到翻页阅读,网上看过立体翻页效果,只是bug太多了还不兼容.看了一下多看阅读翻页是採用平移翻页的,于是就仿写了一个平移翻页的控件.效果例如以下: 在翻页时页面右边缘绘制了阴影.效果还不错.要实现这样的平移翻页控件并不难,仅仅须要定义一个布局管理页面就能够了. 详细实现上有下面难点: 1.循环翻页,页面的反复利用. 2.在翻页时过滤掉

★android开发--ListView+Json+异步网络图片加载+滚动翻页的例子(图片能缓存,图片不错乱)

例子中用于解析Json的Gson请自己Google下载 主Activity: package COM.Example.Main; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Map; import COM.Example.Main.R; import COM.Example.Main.stringG

Android用悬浮按钮实现翻页效果

今天给大家分享下自己用悬浮按钮点击实现翻页效果的例子. 首先,一个按钮要实现悬浮,就要用到系统顶级窗口相关的WindowManager,WindowManager.LayoutParams.那么在AndroidManifest.xml中添加权限: ? 1 <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" /> 然后,我们要对WindowManager,WindowManager.La