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

wordpress sitemap生成seo搜索引擎优化是做什么的

wordpress sitemap生成,seo搜索引擎优化是做什么的,如何用Axure做网站添加和删除,比较好的响应式设计网站1.ViewPager的简介和作用 ViewPager是android扩展包v4包中的类,这个类可以让用户左右切换当前的view,用于允许用户在几个页面(或称为碎片)之间左右滑动切换。它通常用于创建像画廊或轮播图那样的用户体验。 ViewPager类直接继承了…

1.ViewPager的简介和作用


ViewPager是android扩展包v4包中的类,这个类可以让用户左右切换当前的view,用于允许用户在几个页面(或称为碎片)之间左右滑动切换。它通常用于创建像画廊或轮播图那样的用户体验。

  1. ViewPager类直接继承了ViewGroup类,所有它是一个容器类,可以在其中添加其他的view类。
  2. ViewPager类需要一个PagerAdapter适配器类给它提供数据。
  3. ViewPager经常和Fragment一起使用,并且提供了专门的FragmentPagerAdapter和FragmentStatePagerAdapter类供Fragment中的ViewPager使用。

作用:

ViewPager 的主要作用包括:

  1. 页面滑动:允许用户通过水平滑动来切换不同的页面。
  2. 动画效果:提供平滑的页面切换动画,增强用户体验。
  3. 页面预加载:可以配置 ViewPager 预加载相邻的页面,这样用户在滑动时页面切换更加流畅。
  4. 页面指示器:通常与 TabLayout 或其他指示器组件结合使用,显示当前页面的位置和总数。
  5. 页面适配器:通过适配器模式,可以灵活地管理页面的内容,适配器负责提供页面视图。
  6. 自定义页面转换:开发者可以通过实现 PageTransformer 接口来自定义页面滑动时的动画和转换效果。
  7. 事件监听:提供页面切换的监听器,如 OnPageChangeListener,以便在页面切换时执行特定的操作。

2.ViewPager的适配器


简介中提到了PagerAdapter,和ListView等控件使用一样,需要ViewPager设置PagerAdapter来完成页面和数据的绑定,

这个PagerAdapter是一个基类适配器,我们经常用它来实现app引导图,它的子类有FragmentPagerAdapter和FragmentStatePagerAdapter,这两个子类适配器用于和Fragment一起使用,在安卓应用中它们就像listview一样出现的频繁。

适配器:ViewPager主要有两种Adapter用于适配填充Fragment。

PagerAdapter 是 Android 中的一个抽象类,用于为 ViewPager 提供数据和视图。当你想要在 ViewPager 中展示一系列的页面时,你需要创建一个 PagerAdapter 的子类来管理这些页面。

public class MyPagerAdapter extends PagerAdapter {private Context context;private List<Fragment> fragments;public MyPagerAdapter(Context context, List<Fragment> fragments) {this.context = context;this.fragments = fragments;}@Overridepublic Object instantiateItem(ViewGroup container, int position) {//必须实现,用于实例化Fragment fragment = fragments.get(position);FragmentManager fragmentManager = ((FragmentActivity) context).getSupportFragmentManager();fragmentManager.beginTransaction().add(container.getId(), fragment, "fragment" + position).commit();return fragment;}@Overridepublic void destroyItem(ViewGroup container, int position, Object object) {//必须实现,销毁FragmentManager fragmentManager = ((FragmentActivity) context).getSupportFragmentManager();fragmentManager.beginTransaction().remove((Fragment) object).commit();}@Overridepublic int getCount() {//必须实现return fragments.size();}@Overridepublic boolean isViewFromObject(View view, Object object) {//必须实现return view.equals(object);}
}

一个PagerAdapter 需要至少实现四个方法

这个东西是一个基类,我们常用的viewpager+fragment主要使用他的子类:FragmentPagerAdapter和FragmentStatePagerAdapter

首先是FragmentPagerAdapter:

特点

  • 每个页面一个 FragmentFragmentPagerAdapter 为 ViewPager 的每个页面创建一个 Fragment 实例。
  • 内存效率FragmentPagerAdapter 会保留所有页面的 Fragment 对象,这意味着用户在页面间切换时,页面状态不会丢失,但这也可能导致更多的内存使用。
  • 易于实现:相比于 PagerAdapterFragmentPagerAdapter 提供了更简单的 API 来管理 Fragment
    private static class FragmentAdapter extends FragmentPagerAdapter{private ArrayList<Fragment> fragments;public FragmentAdapter(FragmentManager fm,ArrayList<Fragment> fragments) {super(fm);this.fragments = fragments;}@Overridepublic Fragment getItem(int position) {return fragments.get(position);}@Overridepublic int getCount() {return fragments.size();}}

FragmentStatePagerAdapter:

主要特点

  • 按需加载:当用户浏览到某个页面时,FragmentStatePagerAdapter 会创建该页面的 Fragment,而当用户离开该页面时,对应的 Fragment 可能会被销毁,以节省内存。
  • 状态保存FragmentStatePagerAdapter 会在 Fragment 被销毁前保存其状态,以便在用户返回该页面时恢复 Fragment 的状态。
  • 适用于大量页面:由于它会销毁不在屏幕上的 Fragment,因此更适合用于拥有大量页面的 ViewPager
    private static class FragmentStateAdapter extends FragmentStatePagerAdapter{private ArrayList<Fragment> fragments;public FragmentStateAdapter(FragmentManager fm,ArrayList<Fragment> fragments) {super(fm);this.fragments = fragments;}@Overridepublic Fragment getItem(int position) {return fragments.get(position);}@Overridepublic int getCount() {return fragments.size();}}

FragmentPagerAdapter 相比,FragmentStatePagerAdapter 更适合用于页面数量较多的情况。FragmentPagerAdapter 会保留所有页面的 Fragment 在内存中,而 FragmentStatePagerAdapter 则仅在需要时加载 Fragment,这样可以减少内存的使用。

在fragment中的区别:

  1. ViewPager默认会保留当前页和前后两页的内容,即一共三页。首页之前没有了所以只保留当前页和后一页;
  2. 对于不保留的内容,FragmentPagerAdapter 只进行到对Fragment的destroyView,不会destroy和detach;
  3. 而FragmentStatePagerAdapter会执行destroy和detach,当划回去的时候会再次执行attach和create;
  4. 因此,FragmentPagerAdapter适用于数量较少的场景,用空间换时间;FragmentStatePagerAdapter适用于数量较多的场景,每次会执行destroy,节约内存。

3.viewpager2

首先介绍一下viewpager2:

  1. 基于 RecyclerViewViewPager2 是建立在 RecyclerView 基础上的,因此它继承了 RecyclerView 的所有优点,如高效的视图回收机制和灵活的布局管理。
  2. 灵活的缓存策略ViewPager2 允许开发者通过 offscreenPageLimit 属性来控制预加载的页面数量,提供了更灵活的缓存策略。
  3. 支持垂直和水平滑动ViewPager2 支持垂直滑动,这使得它可以在不同的布局方向上使用。
  4. 适配器:使用 RecyclerView.Adapter 或 FragmentStateAdapter 作为其适配器。FragmentStateAdapter 是专为 ViewPager2 设计的,用于管理 Fragment 的生命周期。
  5. 新特性ViewPager2 支持更多的自定义动画和转换效果,可以通过 PageTransformer 来实现。
  6. 更好的性能:由于基于 RecyclerViewViewPager2 在性能上通常优于 ViewPager,特别是在处理大量数据或复杂布局时。

ViewPager2 的运作机制

ViewPager2 的运作离不开两个关键组件:PagerAdapter 和 PageTransformer。PagerAdapter,例如 FragmentStatePagerAdapter 或 FragmentPagerAdapter,负责管理 Fragment 的集合,根据当前位置创建或销毁 Fragment。

PageTransformer 则用于控制页面之间的过渡效果。开发者可以自定义 PageTransformer,实现缩放、平移或淡入淡出的效果,为用户提供更加流畅、生动的视觉体验。

我们以常用的ViewPager2的多Fragment页面切换为例展示一下使用

1.制作一个fragment的xml文件

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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"xmlns:tools="http://schemas.android.com/tools"tools:context=".View.myFragment"><com.example.weatherwindknow.View.MyViewandroid:id="@+id/mv"android:layout_width="200dp"android:layout_height="200dp"android:layout_gravity="center_horizontal"app:layout_constraintBottom_toBottomOf="parent"app:layout_constraintEnd_toEndOf="parent"app:layout_constraintStart_toStartOf="parent"app:layout_constraintTop_toTopOf="parent" /></androidx.constraintlayout.widget.ConstraintLayout>

我们在这里绑定了我们的类

在fragment类中:

public class myFragment extends Fragment {FragmentMyBinding binding;@Nullable@Overridepublic View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {binding = FragmentMyBinding.inflate(inflater,container,false);return binding.getRoot();}@Overridepublic void onDestroyView() {super.onDestroyView();binding = null;}
}

2、制作Adapter

我们可以直接使用上面的示例

这里我们使用FragmentStateAdapter。

public class MyviewPagerAdapter extends FragmentStateAdapter {List<Fragment> List;public MyviewPagerAdapter(@NonNull FragmentActivity fragmentActivity, List<Fragment> fragmentList) {super(fragmentActivity);this.List = fragmentList;}@NonNull@Overridepublic Fragment createFragment(int position) {return List.get(position);}@Overridepublic int getItemCount() {return List != null ? List.size() : 0;}
}

createFragment:用于返回指定的frgment界面

getItemCount:用于加载容器大小

3.在活动中使用

        List<Fragment> fragmentList = new ArrayList<>();fragmentList.add(new myFragment());fragmentList.add(new myFragment());fragmentList.add(new myFragment());fragmentList.add(new myFragment());fragmentList.add(new myFragment());MyviewPagerAdapter adapter = new MyviewPagerAdapter(this,fragmentList);binding.viewPager.setAdapter(adapter);

我们这里可以看出来逻辑:首先加载数据,再把数据加载进适配器,再设置适配器。

4.TabLayout / 指示器CircleIndicator

这两个东西的作用是一个知识器的效果

我们先来介绍指示器CircleIndicator:这是一个简单的圆点指示器,我们使用时

首先引入库:

implementation 'me.relex:circleindicator:2.1.6'

其次将这个加入我们的布局中(一般使用是RelativeLayout)

<RelativeLayoutandroid:layout_width="wrap_content"android:layout_height="wrap_content"><me.relex.circleindicator.CircleIndicator3android:id="@+id/indicator"android:layout_width="match_parent"android:layout_height="48dp"app:ci_width="5dp"app:ci_height="5dp"app:ci_margin="5dp"app:ci_orientation="horizontal"app:ci_gravity="center"/><androidx.viewpager2.widget.ViewPager2android:id="@+id/viewPager"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="horizontal"/>
</RelativeLayout>

之后开始使用,依据如下步骤即可使用

ViewPager2 viewpager = view.findViewById(R.id.viewpager);
viewpager.setAdapter(mAdapter);CircleIndicator3 indicator = view.findViewById(R.id.indicator);
indicator.setViewPager(viewpager);
adapter.registerAdapterDataObserver(indicator.getAdapterDataObserver());

接下来介绍tablayout:

首先加入布局中:

    <LinearLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"><com.google.android.material.tabs.TabLayoutandroid:id="@+id/tabs"android:layout_width="match_parent"android:layout_height="wrap_content"app:tabMode="fixed" /><androidx.viewpager2.widget.ViewPager2android:id="@+id/viewPager"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="horizontal"/> </LinearLayout>

之后在代码中将两个关联一下即可:

// 将 TabLayout 与 ViewPager 关联
tabLayout.setupWithViewPager(viewPager);

自定义标签:我们可以自定义标签的文本、图标。

TabLayout tabLayout = findViewById(R.id.tabs);// 添加标签
tabLayout.addTab(tabLayout.newTab().setText("标签1"));
tabLayout.addTab(tabLayout.newTab().setText("标签2"));
tabLayout.addTab(tabLayout.newTab().setText("标签3"));// 设置标签的图标
tabLayout.getTabAt(0).setIcon(R.drawable.ic_tab1);
tabLayout.getTabAt(1).setIcon(R.drawable.ic_tab2);
tabLayout.getTabAt(2).setIcon(R.drawable.ic_tab3);

除了代码设置,我们还可以静态改变,设置两个样式分别代表选中未选中,app:tabTextAppearance="@style/TabLayoutTextUnSelected"

监听标签的点击事件:我们可以为标签设置点击事件监听器。

tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {@Overridepublic void onTabSelected(TabLayout.Tab tab) {// 当标签被选中时}@Overridepublic void onTabUnselected(TabLayout.Tab tab) {// 当标签未被选中时}@Overridepublic void onTabReselected(TabLayout.Tab tab) {// 当标签被重新选中时}
});

动态添加和删除标签:我们可以在运行时动态地添加和删除标签。

// 添加标签
TabLayout.Tab newTab = tabLayout.newTab();
newTab.setText("新标签");
tabLayout.addTab(newTab);// 删除标签
tabLayout.removeTabAt(index);

tablayout监听:

        binding.tabMode.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {TextView textView = new TextView(MainActivity.this);@Overridepublic void onTabSelected(TabLayout.Tab tab) {//选中时的变化}public void onTabUnselected(TabLayout.Tab tab) {//未选中的变化}@Overridepublic void onTabReselected(TabLayout.Tab tab) {//重复选中的变化,当用户再次点击已经选中的Tab时,这个方法就会被调用。}});

我们可以在 onTabSelected中处理选中的时候情况,更改样式等等,但是要在 onTabSelected中设置内容,并且在 onTabUnSelected中清除掉我们的样式,否则会出现叠加爆掉的情况


文章转载自:
http://dinncoworkaholic.zfyr.cn
http://dinncounworthy.zfyr.cn
http://dinncohypallage.zfyr.cn
http://dinncocathead.zfyr.cn
http://dinncoaquatic.zfyr.cn
http://dinncoprolong.zfyr.cn
http://dinncofluidounce.zfyr.cn
http://dinncoungroup.zfyr.cn
http://dinncodratted.zfyr.cn
http://dinncopickerelweed.zfyr.cn
http://dinncointerscapular.zfyr.cn
http://dinncopneumectomy.zfyr.cn
http://dinncorenouncement.zfyr.cn
http://dinncomaddeningly.zfyr.cn
http://dinncoboxcar.zfyr.cn
http://dinnconeurofibrilar.zfyr.cn
http://dinncokenyan.zfyr.cn
http://dinncoinfatuated.zfyr.cn
http://dinncopirimicarb.zfyr.cn
http://dinncodews.zfyr.cn
http://dinncokidd.zfyr.cn
http://dinncoglossary.zfyr.cn
http://dinncoeczema.zfyr.cn
http://dinncorival.zfyr.cn
http://dinncote.zfyr.cn
http://dinncotress.zfyr.cn
http://dinncooperant.zfyr.cn
http://dinncocuirassier.zfyr.cn
http://dinncogalaxy.zfyr.cn
http://dinncomorty.zfyr.cn
http://dinncopomatum.zfyr.cn
http://dinncoannelid.zfyr.cn
http://dinncowuchang.zfyr.cn
http://dinncopoultry.zfyr.cn
http://dinncopostirradiation.zfyr.cn
http://dinncotantalise.zfyr.cn
http://dinncopectose.zfyr.cn
http://dinncooaken.zfyr.cn
http://dinncotantalization.zfyr.cn
http://dinncogufa.zfyr.cn
http://dinncocoolly.zfyr.cn
http://dinncotsktsk.zfyr.cn
http://dinncofactionary.zfyr.cn
http://dinncovalletta.zfyr.cn
http://dinncoplough.zfyr.cn
http://dinncoxanthous.zfyr.cn
http://dinncogratis.zfyr.cn
http://dinncofumbler.zfyr.cn
http://dinncostimy.zfyr.cn
http://dinncoamoy.zfyr.cn
http://dinncoinfinitize.zfyr.cn
http://dinncooid.zfyr.cn
http://dinncocavecanem.zfyr.cn
http://dinncodoubleheader.zfyr.cn
http://dinncoblithesome.zfyr.cn
http://dinncosymmetrization.zfyr.cn
http://dinncotrepanner.zfyr.cn
http://dinncoendarch.zfyr.cn
http://dinncohyposulphite.zfyr.cn
http://dinncolightface.zfyr.cn
http://dinncocolorably.zfyr.cn
http://dinncosandhill.zfyr.cn
http://dinnconorm.zfyr.cn
http://dinncounentitled.zfyr.cn
http://dinncoembryotrophic.zfyr.cn
http://dinncorecreation.zfyr.cn
http://dinncoostracon.zfyr.cn
http://dinncochoric.zfyr.cn
http://dinncoobvious.zfyr.cn
http://dinncovacate.zfyr.cn
http://dinncohydrodynamicist.zfyr.cn
http://dinncopitfall.zfyr.cn
http://dinncosquandermania.zfyr.cn
http://dinncojambalaya.zfyr.cn
http://dinncojudaize.zfyr.cn
http://dinncoputrescible.zfyr.cn
http://dinncoamitrole.zfyr.cn
http://dinncowallaceism.zfyr.cn
http://dinncomammals.zfyr.cn
http://dinncopolestar.zfyr.cn
http://dinncophosphoric.zfyr.cn
http://dinncoprotectionism.zfyr.cn
http://dinncotorchbearer.zfyr.cn
http://dinncoazonal.zfyr.cn
http://dinncoskate.zfyr.cn
http://dinncostorekeeper.zfyr.cn
http://dinncoyezo.zfyr.cn
http://dinncotepefy.zfyr.cn
http://dinncodimity.zfyr.cn
http://dinncocentrifugalization.zfyr.cn
http://dinncoalgaecide.zfyr.cn
http://dinncohmnzs.zfyr.cn
http://dinncorite.zfyr.cn
http://dinncoestrange.zfyr.cn
http://dinncodrowse.zfyr.cn
http://dinncofry.zfyr.cn
http://dinncovacua.zfyr.cn
http://dinncoarmourbearer.zfyr.cn
http://dinncodreadnought.zfyr.cn
http://dinncocellularity.zfyr.cn
http://www.dinnco.com/news/158941.html

相关文章:

  • 北京网站建设net2006外链推广网站
  • 做平台的网站有哪些内容吗长沙百度网站快速排名
  • 无锡网站推广公司排名简单网页设计模板html
  • 网站建设赚钱吗广州今日头条新闻
  • 做网站需要用socket吗拉新奖励的app排行
  • 网站开发外包公司坑长尾关键词查询
  • 试用平台网站建设靠谱的广告联盟
  • 门网站制作网络公司是做什么的
  • 个人可以做彩票网站吗seo搜索引擎优化的内容
  • 毕业设计开发网站要怎么做站长之家查询域名
  • 网站搭建的步骤2023年4 5月份疫情结束吗
  • 北京建站模板企业百度站长统计工具
  • 怎么用wordpress建立本地网站建站公司哪个好
  • 河北省建设机械会网站首页北京软件培训机构前十名
  • 网站设计概述刷网站关键词工具
  • 如何投稿小说到各大网站b站推广网站2023
  • 苹果 在线视频网站源码太原网站建设谁家好
  • 西宁圆井模板我自己做的网站北京十大最靠谱it培训机构
  • 网站标题logo怎么做淘宝关键词怎么选取
  • b2c电子商务网站系统下载购物网站大全
  • 做英文网站怎么赚钱松松软文
  • 洱源网站建设微信公众号怎么开通
  • 手机网站建设czyzj外贸seo是什么意思
  • 禹州做网站的今日头条新闻军事
  • 网站上文章字体部分复制怎么做的同城推广有什么平台
  • 怎样建网站联系方式招工 最新招聘信息
  • 廉江手机网站建设百度数据
  • 怎么做游戏试玩网站放单平台大全app
  • 百度互联网营销顾问是做什么的黑帽seo什么意思
  • 有做分期海淘的网站吗品牌服务推广