开发工具:
文件大小: 2mb
下载次数: 0
上传时间: 2015-06-26
详细说明:
主界面 Fragment布局 主代码 package com.example.text; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentPagerAdapter; import android.support.v4.view.ViewPager; import android.support.v4.view.ViewPager.OnPageChangeListener; import android.support.v7.app.ActionBarActivity; import android.os.Bundle; import android.util.DisplayMetrics; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup.LayoutParams; import android.view.animation.LinearInterpolator; import android.view.animation.TranslateAnimation; import android.widget.HorizontalScrollView; import android.widget.ImageView; import android.widget.RadioButton; import android.widget.RadioGroup; import android.widget.TextView; import android.widget.RadioGroup.OnCheckedChangeListener; public class MainActivity extends FragmentActivity { private HorizontalScrollView scrollview; private RadioGroup radioGroup; private ImageView sayit_lines; private ViewPager viewPager; private LayoutInflater inflater; private TabFragmentPagerAdapter adapter; private int tageDistance = 0; private int initWidth; public static String[] tabTitle = {"全部", "南京", "上海", "南方", "金马甲", "福利特","江苏" }; //标题 public static final String ARGUMENTS_NAME = "arg"; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); scrollview = (HorizontalScrollView) findViewById(R.id.sayit_ScrollView); radioGroup = (RadioGroup) findViewById(R.id.sayit_radioGroup); sayit_lines = (ImageView) findViewById(R.id.sayit_lines); viewPager = (ViewPager) findViewById(R.id.sayit_viewPager); initView(); setListener(); } private void setListener(){ viewPager.setOnPageChangeListener(new OnPageChangeListener() { public void onPageSelected(int position) { // TODO Auto-generated method stub if (radioGroup!=null && radioGroup.getChildCount()>position) { ((RadioButton)radioGroup.getChildAt(position)).performClick(); } } public void onPageScrolled(int arg0, float arg1, int arg2) { // TODO Auto-generated method stub } public void onPageScrollStateChanged(int arg0) { // TODO Authio-generated method stub } }); radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { // TODO Auto-generated method stub if(radioGroup.getChildAt(checkedId)!=null){ //创建动画对象 TranslateAnimation animation = new TranslateAnimation( //起始坐标 tageDistance , //获取当前RadioButton最左边的坐标值 为最终坐标 ((RadioButton) radioGroup.getChildAt(checkedId)).getLeft(), 0f, 0f); //设置此动画的加速度曲线 变化速率恒定 animation.setInterpolator(new LinearInterpolator()); //动画事件 animation.setDuration(400); animation.setFillAfter(true); //执行位移动画 sayit_lines.startAnimation(animation); viewPager.setCurrentItem(checkedId); //ViewPager 跟随一起 切换 //记录当前 下标的距最左侧的 距离 tageDistance = ((RadioButton) radioGroup.getChildAt(checkedId)).getLeft(); //设置当标题改变时 HorizontalScrollView 移动的距离 //如果标题是第3个及大于第3个时 获取当前标题左端的x坐标值 否则 为 0 int x1=checkedId > 1 ? ((RadioButton) radioGroup.getChildAt(checkedId)).getLeft() : 0; //获取第2个标题左端的x坐标值 int x2=((RadioButton) radioGroup.getChildAt(1)).getLeft(); //计算x轴方向移动的距离 int x=x1-x2; scrollview.smoothScrollTo(x,0); } } }); } private void initView(){ DisplayMetrics dm = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(dm); initWidth = dm.widthPixels / 3; LayoutParams params = sayit_lines.getLayoutParams(); params.width = (initWidth-20);// 初始化滑动下标的宽度 sayit_lines.setLayoutParams(params); //加载滑动下标的宽度 inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE); initNavigationHSV(); adapter = new TabFragmentPagerAdapter(getSupportFragmentManager()); viewPager.setAdapter(adapter); } private void initNavigationHSV(){ radioGroup.removeAllViews(); for(int i=0;i
(系统自动生成,下载前可以参看下载内容)
下载文件列表
相关说明
- 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
- 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度。
- 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
- 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
- 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
- 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.