Fragment滑动切换Bar动画
来源:互联网 发布:求生之路2不同网络 编辑:程序博客网 时间:2024/05/22 03:34
布局
<span style="font-size:18px;"><?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"> <!--我的订单--> <include layout="@layout/base_title_1" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/text_white" android:orientation="horizontal"> <RelativeLayout android:id="@+id/rl1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1"> <TextView android:id="@+id/tv_1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:layout_marginTop="20dp" android:text="待支付" android:textColor="@color/Theme_color" android:textSize="15sp" /> </RelativeLayout> <RelativeLayout android:id="@+id/rl2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1"> <TextView android:id="@+id/tv_2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:layout_marginTop="20dp" android:text="运送中" android:textColor="@color/Text_black" android:textSize="15sp" /> </RelativeLayout> <RelativeLayout android:id="@+id/rl3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1"> <TextView android:id="@+id/tv_3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:layout_marginTop="20dp" android:text="已完成" android:textColor="@color/Text_black" android:textSize="15sp" /> </RelativeLayout> </LinearLayout> <ImageView android:id="@+id/id_tab_line_iv" android:layout_width="50dp" android:layout_height="2.5dp" android:layout_centerHorizontal="true" android:background="@color/Theme_color" /> <com.lixin.zhongshitongapp.app.view.LazyViewPager android:id="@+id/ViewPager" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" /></LinearLayout></span>
ViewPager代码
监听
public class Pagechage implements LazyViewPager.OnPageChangeListener { @Override public void onPageScrollStateChanged(int arg0) { // TODO Auto-generated method stub if (arg0 == 2) { int i = viewPager.getCurrentItem(); clean();//清除选中状态 count(i);//选中监听 } } @Override public void onPageScrolled(int arg0, float arg1, int arg2) { // TODO Auto-generated method stub /** * arg0 :当前页面,及你点击滑动的页面 arg1:当前页面偏移的百分比 * arg2:当前页面偏移的像素位置 */ LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) id_tab_line_iv.getLayoutParams(); if (currentIndex == 0 && arg0 == 0)// 0->1 { lp.leftMargin = (int) (arg1 * (screenWidth * 1.0 / 3) + currentIndex * (screenWidth / 3)); } else if (currentIndex == 1 && arg0 == 0) // 1->0 { lp.leftMargin = (int) (-(1 - arg1) * (screenWidth * 1.0 / 3) + currentIndex * (screenWidth / 3)); } else if (currentIndex == 1 && arg0 == 1) // 1->2 { lp.leftMargin = (int) (arg1 * (screenWidth * 1.0 / 3) + currentIndex * (screenWidth / 3)); } else if (currentIndex == 2 && arg0 == 1) // 2->1 { lp.leftMargin = (int) (-(1 - arg1) * (screenWidth * 1.0 / 3) + currentIndex * (screenWidth / 3)); } id_tab_line_iv.setLayoutParams(lp); } @Override public void onPageSelected(int arg0) { // TODO Auto-generated method stub currentIndex = arg0; } }
在onCreate()方法加入
/** * 设置滑动条的宽度为屏幕的1/3(根据Tab的个数而定) */ private void initTabLineWidth() { DisplayMetrics dpMetrics = new DisplayMetrics(); getWindow().getWindowManager().getDefaultDisplay().getMetrics(dpMetrics); screenWidth = dpMetrics.widthPixels; LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) id_tab_line_iv.getLayoutParams(); lp.width = screenWidth / 3; id_tab_line_iv.setLayoutParams(lp); }
private class Click implements View.OnClickListener { @Override public void onClick(View arg0) { // TODO Auto-generated method stub clean(); count(arg0.getId()); } }
1 0
- Fragment滑动切换Bar动画
- Android Fragment滑动切换
- Fragment切换动画
- Fragment切换动画
- Android Fragment切换动画
- activity、fragment切换动画
- Fragment切换动画
- ViewPage Fragment 页面滑动切换
- ViewPager+Fragment滑动切换界面
- 左右滑动动画切换屏幕
- android界面切换滑动动画
- viewpager禁止滑动切换动画
- 监听Fragment的切换动画
- Fragment,Activity切换动画--Demo
- activity与fragment切换动画
- Android Fragment切换动画效果
- Activity与Fragment切换动画
- Activity与Fragment切换动画
- 黄绿色——三色配色篇
- Android —— 联系人索引效果
- webuploader.js谷歌浏览器本地调用点击上传文件选择框会延迟几秒才会显示
- Naive Bayes算法(NB算法---朴素贝叶斯)
- Executor框架线程池任务执行全过程原理
- Fragment滑动切换Bar动画
- 消除字符串中成对的括号
- 关于用户分级查看的解决方案
- WebUploader UEditor chrome 点击上传文件选择框会延迟几秒才会显示
- 黄绿色——五色配色篇
- Android Studio常用功能配置,让开发更高效(一)
- 根据Requet请求获取IP地址
- MySql ibdata1文件太大如何缩小
- 解决Win7&Win8 64位下Source Insight提示未完整安装的问题