ZJ_HorizontalScrollView.rar

  • WeiQiPro
    了解作者
  • Java
    开发工具
  • 305KB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • 1 积分
    下载积分
  • 105
    下载次数
  • 2012-10-18 16:49
    上传日期
Android 实现Activity间横向滑屏。
ZJ_HorizontalScrollView.rar
内容介绍
package com.zj.horizontalsrollview; 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.util.Log; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup.MarginLayoutParams; import android.view.animation.Animation; import android.view.animation.AnimationSet; import android.view.animation.AnimationUtils; import android.view.animation.TranslateAnimation; import android.widget.HorizontalScrollView; import android.widget.ImageView; import android.widget.RadioButton; import android.widget.RadioGroup; import android.widget.RadioGroup.OnCheckedChangeListener; import android.widget.RelativeLayout; import android.widget.RelativeLayout.LayoutParams; /** * HorizontalScrollView和ViewPager联动效果 * 上面为HorizontalScrollView,下面为ViewPager * @author zj * 2012-5-23 下午1:07:06 */ public class MainActivity extends Activity implements OnCheckedChangeListener{ private RadioGroup mRadioGroup; private RadioButton mRadioButton1; private RadioButton mRadioButton2; private RadioButton mRadioButton3; private RadioButton mRadioButton4; private RadioButton mRadioButton5; private ImageView mImageView; private float mCurrentCheckedRadioLeft;//当前被选中的RadioButton距离左侧的距离 private HorizontalScrollView mHorizontalScrollView;//上面的水平滚动控件 private ViewPager mViewPager; //下方的可横向拖动的控件 private ArrayList<View> mViews;//用来存放下方滚动的layout(layout_1,layout_2,layout_3) @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); iniController(); iniListener(); iniVariable(); mRadioButton1.setChecked(true); mViewPager.setCurrentItem(1); mCurrentCheckedRadioLeft = getCurrentCheckedRadioLeft(); } private void iniVariable() { // TODO Auto-generated method stub mViews = new ArrayList<View>(); mViews.add(getLayoutInflater().inflate(R.layout.layout_0, null)); mViews.add(getLayoutInflater().inflate(R.layout.layout_1, null)); mViews.add(getLayoutInflater().inflate(R.layout.layout_2, null)); mViews.add(getLayoutInflater().inflate(R.layout.layout_3, null)); mViews.add(getLayoutInflater().inflate(R.layout.layout_4, null)); mViews.add(getLayoutInflater().inflate(R.layout.layout_5, null)); mViews.add(getLayoutInflater().inflate(R.layout.layout_0, null)); mViewPager.setAdapter(new MyPagerAdapter());//设置ViewPager的适配器 } /** * RadioGroup点击CheckedChanged监听 */ @Override public void onCheckedChanged(RadioGroup group, int checkedId) { AnimationSet _AnimationSet = new AnimationSet(true); TranslateAnimation _TranslateAnimation; Log.i("zj", "checkedid="+checkedId); if (checkedId == R.id.btn1) { _TranslateAnimation = new TranslateAnimation(mCurrentCheckedRadioLeft, getResources().getDimension(R.dimen.rdo1), 0f, 0f); _AnimationSet.addAnimation(_TranslateAnimation); _AnimationSet.setFillBefore(false); _AnimationSet.setFillAfter(true); _AnimationSet.setDuration(100); /*LayoutParams _LayoutParams1 = new LayoutParams(100, 4); _LayoutParams1.setMargins(0, 0, 0, 0); _LayoutParams1.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);*/ //mImageView.bringToFront(); mImageView.startAnimation(_AnimationSet);//开始上面蓝色横条图片的动画切换 //mImageView.setLayoutParams(_LayoutParams1); mViewPager.setCurrentItem(1);//让下方ViewPager跟随上面的HorizontalScrollView切换 }else if (checkedId == R.id.btn2) { _TranslateAnimation = new TranslateAnimation(mCurrentCheckedRadioLeft, getResources().getDimension(R.dimen.rdo2), 0f, 0f); _AnimationSet.addAnimation(_TranslateAnimation); _AnimationSet.setFillBefore(false); _AnimationSet.setFillAfter(true); _AnimationSet.setDuration(100); //mImageView.bringToFront(); mImageView.startAnimation(_AnimationSet); mViewPager.setCurrentItem(2); }else if (checkedId == R.id.btn3) { _TranslateAnimation = new TranslateAnimation(mCurrentCheckedRadioLeft, getResources().getDimension(R.dimen.rdo3), 0f, 0f); _AnimationSet.addAnimation(_TranslateAnimation); _AnimationSet.setFillBefore(false); _AnimationSet.setFillAfter(true); _AnimationSet.setDuration(100); //mImageView.bringToFront(); mImageView.startAnimation(_AnimationSet); mViewPager.setCurrentItem(3); }else if (checkedId == R.id.btn4) { _TranslateAnimation = new TranslateAnimation(mCurrentCheckedRadioLeft, getResources().getDimension(R.dimen.rdo4), 0f, 0f); _AnimationSet.addAnimation(_TranslateAnimation); _AnimationSet.setFillBefore(false); _AnimationSet.setFillAfter(true); _AnimationSet.setDuration(100); //mImageView.bringToFront(); mImageView.startAnimation(_AnimationSet); mViewPager.setCurrentItem(4); }else if (checkedId == R.id.btn5) { _TranslateAnimation = new TranslateAnimation(mCurrentCheckedRadioLeft, getResources().getDimension(R.dimen.rdo5), 0f, 0f); _AnimationSet.addAnimation(_TranslateAnimation); _AnimationSet.setFillBefore(false); _AnimationSet.setFillAfter(true); _AnimationSet.setDuration(100); //mImageView.bringToFront(); mImageView.startAnimation(_AnimationSet); mViewPager.setCurrentItem(5); } mCurrentCheckedRadioLeft = getCurrentCheckedRadioLeft();//更新当前蓝色横条距离左边的距离 Log.i("zj", "getCurrentCheckedRadioLeft="+getCurrentCheckedRadioLeft()); Log.i("zj", "getDimension="+getResources().getDimension(R.dimen.rdo2)); mHorizontalScrollView.smoothScrollTo((int)mCurrentCheckedRadioLeft-(int)getResources().getDimension(R.dimen.rdo2), 0); } /** * 获得当前被选中的RadioButton距离左侧的距离 */ private float getCurrentCheckedRadioLeft() { // TODO Auto-generated method stub if (mRadioButton1.isChecked()) { //Log.i("zj", "currentCheckedRadioLeft="+getResources().getDimension(R.dimen.rdo1)); return getResources().getDimension(R.dimen.rdo1); }else if (mRadioButton2.isChecked()) { //Log.i("zj", "currentCheckedRadioLeft="+getResources().getDimension(R.dimen.rdo2)); return getResources().getDimension(R.dimen.rdo2); }else if (mRadioButton3.isChecked()) { //Log.i("zj", "currentCheckedRadioLeft="+getResources().getDimension(R.dimen.rdo3)); return getResources().getDimension(R.dimen.rdo3); }else if (mRadioButton4.isChecked()) { //Log.i("zj", "currentCheckedRadioLeft="+getResources().getDimension(R.dimen.rdo4)); return getResources().getDimension(R.dimen.rdo4); }else if (mRadioButton5.isChecked()) { //Log.i("zj", "currentCheckedRadioLeft="+getResources().getDimension(R.dimen.rdo5)); return getResources().getDimension(R.dimen.rdo5); } return 0f; } private void iniListener() { // TODO Auto-generated method stub mRadioGroup.setOnCheckedChangeListener(this); mViewPager.setOnPageChangeListener(new MyPagerOnPageChangeListener()); } private void iniController() { // TODO Auto-generated method stub mRadioGroup = (RadioGroup)findViewById(R.id.radioGroup); mRadioButton1 = (RadioButton)findViewById(R.id.btn1); mRadioButton2 = (RadioButton)findViewById(R.id.btn2); mRadioButton3 = (RadioButton)findViewById(R.id.btn3); mRadioButton4 = (RadioButton)findViewById(R.id.btn4); mRadioButton5 = (RadioButton)findViewById(R.id.btn5); mImageView = (ImageView)findViewById(R.id.img1); mHorizontalScrollView = (HorizontalScrollView)findViewById(R.id.horizontalScrollView); mViewPager = (ViewPager)findViewById(R.id.pager); } /** * ViewPager的适配器 * @author zj * 2012-5-24 下午2:26:57 */ private class MyPagerAdapter extends PagerAdapter{ @Override public void destroyItem(View v, int positio
评论
    相关推荐
    • Android-LogCat-tool.zip
      LogCat是Android中一个命令行工具,可以用于得到程序的log信息,本附录讲解其使用方法和其中的一些技巧。
    • android_calculate.rar
      超级清爽android计算器界面源码,完成可用。可以供初学者参考。
    • android调用相机和相册.zip
      android studio上可以进行手机摄像头和相册的调用
    • SwipeListViewDemo.rar
      仿微信列表(ListView)滑动删除源码SwipeListViewDemo,效果也比较不错的,源码很清晰
    • 8-1(迷宫小球).rar
      一个小球走迷宫的安卓小游戏,小球在重力引导下走出迷宫
    • RecyclerViewTest.zip
      android recyclerview 的基本使用,欢迎大家下载学习!
    • AndResGuard-master.zip
      修改项目中资源文件的id名称,并创建新的关联,实现减小apk包的大小
    • HarmonyOS和android-Hydrogen-Browser:氢浏览器
      Android 和鸿蒙操作系统上的移动浏览器。 发行说明 v0.3.0_alpha 发布日期:2021 年 6 月 4 日 优化:RecyclerView 重构设置页面 优化:将项目重构为不同的包 修复:退出应用程序时没有动画 v0.2.4_alpha 发布日期:...
    • MyApplicationUI.rar
      简单的登录选择头像界面,Android 移动平台的
    • ZxingDemo.rar
      android上使用ZXing识别条形码和二维码,代码简单易懂,相信能帮助读者迅速掌握相关的开发