当前位置: 首页 > news >正文

web程序设计网站开发工具/制作网站费用

web程序设计网站开发工具,制作网站费用,原创网站源码,软件行业发展趋势款APP开始的时候往往少不了多页面的切换,这就涉及到viewpager的使用,以前往往用Google自带的效果去实现,比较麻烦不说,后面做出来的效果还不如人意。 下面就利用CommonTabLayoutViewPager来实现类似各电商APP首页的效果&#xff1…

 款APP开始的时候往往少不了多页面的切换,这就涉及到viewpager的使用,以前往往用Google自带的效果去实现,比较麻烦不说,后面做出来的效果还不如人意。

下面就利用CommonTabLayout+ViewPager来实现类似各电商APP首页的效果;

搭建很简单,第一步,新建一个工程。在build.gradle里面加入下面的引用:

compile 'com.flyco.roundview:FlycoRoundView_Lib:1.1.2@aar'
compile 'com.flyco.tablayout:FlycoTabLayout_Lib:1.5.0@aar'
compile 'com.android.support:design:24.2.1'compile 'com.nineoldandroids:library:2.4.0'

这样就能使用CommTabLayout插件了;

下面是activity_main.xml文件,我在里面加入了一个FloatingActionButton。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"><RelativeLayoutandroid:layout_width="match_parent"android:layout_height="0dp"android:layout_weight="1"><android.support.v4.view.ViewPagerandroid:id="@+id/view_main"android:layout_width="match_parent"android:layout_height="match_parent"/><android.support.design.widget.FloatingActionButtonandroid:id="@+id/float_button"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentBottom="true"android:layout_alignParentRight="true"android:layout_marginBottom="10dp"android:layout_marginRight="10dp"app:backgroundTint="#FFFFFF"android:background="@drawable/ic_arrow_drop_down_black_24dp"/></RelativeLayout><com.flyco.tablayout.CommonTabLayoutandroid:id="@+id/tab_main"android:layout_width="match_parent"android:layout_height="40dp"android:background="#FFFFFF"app:tl_iconGravity="LEFT"app:tl_iconHeight="20dp"app:tl_iconMargin="5dp"app:tl_iconWidth="20dp"app:tl_indicator_bounce_enable="false"app:tl_indicator_color="@color/colorPrimary"app:tl_indicator_gravity="TOP"app:tl_textSelectColor="@color/colorPrimary"app:tl_textUnselectColor="#DDD"app:tl_textsize="15sp"app:tl_underline_color="#DDDDDD"app:tl_underline_gravity="TOP"app:tl_underline_height="1dp"/></LinearLayout>

先创建几个fagment用来做viewPager的元素,我在viewPager里面加了三个fragment,都是非常简单的布局;这些fragment继承了我自己创建的一个BaseFragment;

BaseFragment

package com.learn.bob.testfragmentadapter;import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;public class BaseFragment extends Fragment {public int dialogTheme;public Context mContext;@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);}@Overridepublic void onPause() {super.onPause();}@Overridepublic void onResume() {super.onResume();}}

 

package com.learn.bob.testfragmentadapter;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

/**
* Created by Administrator on 2018/1/7.
*/

public class ThirdFragment extends BaseFragment {

private Context mContext;

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
mContext = getActivity();
return inflater.inflate(R.layout.fragment_thirdd, container, false);
}

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
initView();
}

private void initView(){

}
}

 

下面是MainActivity,

package com.learn.bob.testfragmentadapter;import android.support.design.widget.FloatingActionButton;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;import com.flyco.tablayout.CommonTabLayout;
import com.flyco.tablayout.listener.CustomTabEntity;
import com.flyco.tablayout.listener.OnTabSelectListener;import java.util.ArrayList;
import java.util.List;public class MainActivity extends AppCompatActivity{private ViewPager mViewPager;private CommonTabLayout mTab;private FirstFragment firstFragment;private FirstReplaceFragment firstReplaceFragment;private SecondFragment secondFragment;private ThirdFragment thirdFragment;private ViewPagerAadpter viewPagerAadpter;private List<BaseFragment> fragmentList;private ArrayList<CustomTabEntity> mTabEntities = new ArrayList<>();private FloatingActionButton mBtn;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);initView();}private void initView(){mViewPager = (ViewPager)findViewById(R.id.view_main);mTab = (CommonTabLayout) findViewById(R.id.tab_main);mBtn = (FloatingActionButton)findViewById(R.id.float_button);mBtn.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View view) {if(null != firstFragment){// Toast.makeText(MainActivity.this,"点击了",Toast.LENGTH_LONG).show();
                }}});if(null == fragmentList){fragmentList = new ArrayList<BaseFragment>();}if(null  == firstFragment){firstFragment = new FirstFragment();fragmentList.add(firstFragment);mTabEntities.add(new TabEntity("首页",R.mipmap.ic_launcher,R.mipmap.ic_launcher));}if(null == secondFragment){secondFragment = new SecondFragment();fragmentList.add(secondFragment);mTabEntities.add(new TabEntity("扉页",R.mipmap.ic_launcher,R.mipmap.ic_launcher));}if(null == thirdFragment){thirdFragment = new ThirdFragment();fragmentList.add(thirdFragment);mTabEntities.add(new TabEntity("尾页",R.mipmap.ic_launcher,R.mipmap.ic_launcher));}viewPagerAadpter = new ViewPagerAadpter(getSupportFragmentManager(),fragmentList);mViewPager.setAdapter(viewPagerAadpter);mTab.setTabData(mTabEntities);mViewPager.setOffscreenPageLimit(3);

//为tab页的点击添加监听事件mTab.setOnTabSelectListener(
new OnTabSelectListener() {@Overridepublic void onTabSelect(int position) {mViewPager.setCurrentItem(position);}@Overridepublic void onTabReselect(int position) {}});
//为viewPager的滑动添加监听事件mViewPager.addOnPageChangeListener(
new ViewPager.OnPageChangeListener() {@Overridepublic void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {}@Overridepublic void onPageSelected(int position) {mTab.setCurrentTab(position);}@Overridepublic void onPageScrollStateChanged(int state) {}}); }
//viewPager的适配器
private class ViewPagerAadpter extends FragmentPagerAdapter{private List<BaseFragment> fragments;private FragmentManager fragmentManager;public ViewPagerAadpter(FragmentManager fm, List<BaseFragment> fragmentList) {super(fm);this.fragments = fragmentList;this.fragmentManager = fm;}@Overridepublic Fragment getItem(int position) {return fragments.get(position);}@Overridepublic int getCount() {return fragments.size();}}}

在CusstommonTabEntity的基础上我添加了一个TabEntity的实体类来定义我的tab页;

package com.learn.bob.testfragmentadapter;import com.flyco.tablayout.listener.CustomTabEntity;/*** Created by bob on 2017-4-12 14:37*/public class TabEntity implements CustomTabEntity {public String title;public int selectedIcon;public int unSelectedIcon;public TabEntity(String title, int selectedIcon, int unSelectedIcon) {this.title = title;this.selectedIcon = selectedIcon;this.unSelectedIcon = unSelectedIcon;}public TabEntity(String title) {this.title = title;}@Overridepublic String getTabTitle() {return title;}@Overridepublic int getTabSelectedIcon() {return selectedIcon;}@Overridepublic int getTabUnselectedIcon() {return unSelectedIcon;}
}

这是最终的效果,在xml里面能够设置下面tab页滑动时线条文字显示的颜色,也可以设置成无线条

 

项目GitHub地址:https://github.com/bobLion/TestFragmentAdapte.git

转载于:https://www.cnblogs.com/BobAdmin/p/8267203.html

http://www.jmfq.cn/news/5267809.html

相关文章:

  • 用win2008做网站/今日国内重大新闻事件
  • wordpress电影模板下载/如何将网站的关键词排名优化
  • iis6 网站无法访问/公司网站
  • 烟台做网站的公司/游戏推广员好做吗
  • wordpress模板 更换/seo刷关键词排名免费
  • 石家庄市最新公告/苏州整站优化
  • 吉林seo基础知识/上首页seo
  • 网站建设费用:做个网站要多少钱?/影视剪辑培训机构排名
  • 自己做网站能宣传自己的产品吗/网络推广员为什么做不长
  • 北京建设网站的公司兴田德润优惠/seo 优化顾问
  • 营销型网站 开源程序/大数据营销系统软件
  • 做美女网站挣钱/百度首页关键词推广
  • 兰州企业做网站/软文写作服务
  • 海南智能网站建设公司/外贸独立站推广
  • 网页的制作教案/成都网站seo厂家
  • 做公司网站需要准备什么/怎么有自己的网站
  • 重庆金融网站建设/搜索引擎优化心得体会
  • 网站制作团队分工/网站seo价格
  • 深圳有哪些网站是做餐饮沙龙的/关键词优化公司排名榜
  • 做电影网站犯罪吗/百度灰色词排名代发
  • 长沙做网站kaodezhu/seo手机关键词网址
  • 建设百度网站/seo费用
  • 上海高端工作室网站/网络推广公司可不可靠
  • 建设银行网站怎么设置转账额度/产品运营主要做什么
  • 网站手机站怎么做的/代刷网站推广
  • 长沙网站制作费用/河源新闻最新消息
  • 广西网站建设价格/app推广在哪里可以接单
  • wordpress新建页面不能保存路径/贵州快速整站优化
  • 泊头做网站的/百度竞价推广效果怎么样
  • 整站优化温州怎么做?/网上国网app