android 滑动分页

  • y7_486968
    了解作者
  • 2.2MB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-04-18 11:37
    上传日期
TabHost滑动分页,网上找的资源,加入自己的想法,实现,效果有点搓,但是功能都实现了。上源码!
tabHostDemo.rar
内容介绍
package com.wxw.activity; import java.util.ArrayList; import java.util.List; import android.app.Activity; import android.graphics.Color; import android.os.Bundle; import android.support.v4.view.ViewPager; import android.support.v4.view.ViewPager.OnPageChangeListener; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.widget.EditText; import android.widget.RelativeLayout; import android.widget.TextView; import com.wxw.adpter.MyPagerAdapter; public class TabHostDemoActivity extends Activity { /** Called when the activity is first created. */ private ViewPager myViewPager; private MyPagerAdapter myAdapter; private LayoutInflater mInflater; private List<View> listViews; private EditText editText1, editText2, editText3; private View layout1 = null; private View layout2 = null; private View layout3 = null; private View viewElement = null; private TextView textView1, textView2, textView3; private RelativeLayout relativeLayout1, relativeLayout2, relativeLayout3; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); this.getViewById(); relativeLayout1.setOnClickListener(new OnClickListener() { public void onClick(View v) { setImageBackground(0); myViewPager.setCurrentItem(0); } }); relativeLayout2.setOnClickListener(new OnClickListener() { public void onClick(View v) { setImageBackground(1); myViewPager.setCurrentItem(1); } }); relativeLayout3.setOnClickListener(new OnClickListener() { public void onClick(View v) { setImageBackground(2); myViewPager.setCurrentItem(2); } }); listViews = new ArrayList<View>(); mInflater = getLayoutInflater(); layout1 = mInflater.inflate(R.layout.help1, null); layout2 = mInflater.inflate(R.layout.help2, null); layout3 = mInflater.inflate(R.layout.help3, null); listViews.add(layout1); listViews.add(layout2); listViews.add(layout3); myAdapter = new MyPagerAdapter(listViews); myViewPager.setAdapter(myAdapter); myViewPager.setCurrentItem(0); /** * viewPage页面改變监听器 */ myViewPager.setOnPageChangeListener(new OnPageChangeListener() { public void onPageSelected(int arg0) { viewElement = listViews.get(arg0); // activity从1到2滑动,2被加载后掉用此方法 switch (arg0) { case 0: editText1 = (EditText) findViewById(R.id.one); editText1.setText("常规查询"); setImageBackground(0); break; case 1: editText2 = (EditText) findViewById(R.id.two); editText2.setText("周边查询"); setImageBackground(1); break; case 2: editText3 = (EditText) findViewById(R.id.three); editText3.setText("快速通道"); setImageBackground(2); break; default: break; } } public void onPageScrolled(int arg0, float arg1, int arg2) { // 从1到2滑动,在1滑动前调用 } public void onPageScrollStateChanged(int arg0) { Log.d("k", "onPageScrollStateChanged - " + arg0); // 状态有三个0空闲,1是增在滑行中,2目标加载完毕 } }); } /** * 通过id获取控件 */ private void getViewById() { // 顶部的三个tab标签 relativeLayout1 = (RelativeLayout) findViewById(R.id.rmml1); relativeLayout2 = (RelativeLayout) findViewById(R.id.rmml2); relativeLayout3 = (RelativeLayout) findViewById(R.id.rmml3); textView1 = (TextView) relativeLayout1.findViewById(R.id.textView1); textView2 = (TextView) relativeLayout2.findViewById(R.id.textView2); textView3 = (TextView) relativeLayout3.findViewById(R.id.textView3); myViewPager = (ViewPager) findViewById(R.id.myMesPager); } private void setImageBackground(int position) { switch (position) { case 0: relativeLayout1.setBackgroundResource(R.drawable.focus); relativeLayout2.setBackgroundResource(R.drawable.no_focus); relativeLayout3.setBackgroundResource(R.drawable.no_focus); textView1.setTextColor(Color.WHITE); textView2.setTextColor(Color.GRAY); textView3.setTextColor(Color.GRAY); break; case 1: relativeLayout1.setBackgroundResource(R.drawable.no_focus); relativeLayout2.setBackgroundResource(R.drawable.focus); relativeLayout3.setBackgroundResource(R.drawable.no_focus); textView1.setTextColor(Color.GRAY); textView2.setTextColor(Color.WHITE); textView3.setTextColor(Color.GRAY); break; case 2: relativeLayout1.setBackgroundResource(R.drawable.no_focus); relativeLayout2.setBackgroundResource(R.drawable.no_focus); relativeLayout3.setBackgroundResource(R.drawable.focus); textView1.setTextColor(Color.GRAY); textView2.setTextColor(Color.GRAY); textView3.setTextColor(Color.WHITE); break; default: break; } } }
评论
    相关推荐
    • Android学习
      Android学习Android学习Android学习Android学习Android学习Android学习
    • Android678
      Android678Android678Android678Android678Android678Android678Android678Android678Android678Android678
    • android 例子
      android 例子android 例子android 例子android 例子android 例子
    • android图片
      android精美小图片android精美小图片android精美小图片android精美小图片
    • android课件
      清华老师上课的android课件。ch_01android概述ch_02android开发基础ch_03资源的访问ch_04android用户界面ch_05Ativity和Intent。其他自己看。
    • AndroidKiller
      安卓App反编译工具AndroidKiller\AndroidKiller\AndroidKiller
    • AndroidSample
      Android示例 这是一个示例Android应用,用于降低Google Play服务和Android Volley的使用率。 有关更多详细信息,请参阅以下链接: Google Play服务: Android凌空抽射:
    • android source
      android 源代码 source android 源代码 source android 源代码 source android 源代码 source android 源代码 source android 源代码 source android 源代码 source
    • Android 教程
      Android 案例 教程,Android 案例 教程,Android 案例 教程,Android 案例 教程,Android 案例 教程,Android 案例 教程,Android 案例 教程,Android 案例 教程,Android 案例 教程,Android 案例 教程,Android ...
    • android资料
      Android程序员指南 Android_UI开发专题 Android程序开发初级教程 android的五大类各种常用类的资料整理 Android高手进阶教程