Android实现横向滑动卡片效果

发布时间:2020-09-04 22:51:17

来源:脚本之家

阅读:255

作者:itbobby

最近项目上需要实现这样效果的一个页面,本来想找个现成的两下搞定,但是问了半天度娘也没招,索性自己琢磨琢磨(这里边也少不了同事的帮助),先把最终的效果图贴上:

理论上讲,其本质并不复杂,就是一个viewpager,但是第一次实现这样的效果还是要花些时间的,具体的代码如下:

主布局文件:activity_show_industry_list.xml,主要就是一个activity上放个viewpager,但是相对布局是关键

android:layout_width="match_parent" android:layout_height="match_parent"

xmlns:app="http://schemas.android.com/apk/res-auto"

android:orientation="vertical"

android:background="@color/colorGrayBg">

android:layout_width="match_parent"

android:layout_height="wrap_content"

app:titleText="搜索框预留位置"

app:showBackButton="true"

android:id="@+id/titleView" />

android:layout_width="match_parent"

android:layout_height="match_parent"

android:clipChildren="false"

android:layerType="software"

android:id="@+id/awq_rl_vpc">

android:id="@+id/vp_show_industry_list"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_gravity="center"

android:clipChildren="false"

android:layout_marginLeft="40dp"

android:layout_marginRight="40dp"

android:layout_marginBottom="90dp" />

fragment布局文件:fragment_show_industry_list.xml  该布局对应的类比较简单,就不往上贴了

xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"

android:layout_height="match_parent" tools:context="huazheng.haiereng.BlankFragment"

android:orientation="vertical"

android:background="@color/colorWhite">

android:orientation="vertical"

android:layout_width="match_parent"

android:layout_height="300dp" >

android:layout_width="match_parent"

android:layout_height="match_parent"

android:id="@+id/iv_show_industry_list_pic"

android:background="@mipmap/show_industry_detail"

android:layout_gravity="center_horizontal" />

android:layout_width="match_parent"

android:layout_height="35dp"

android:layout_gravity="bottom"

android:alpha="0.5"

android:background="#333" />

android:layout_width="wrap_content"

android:layout_height="35dp"

android:layout_gravity="center_horizontal|bottom"

android:id="@+id/frameLayout" >

android:orientation="horizontal"

android:layout_width="match_parent"

android:layout_height="match_parent" >

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:textAppearance="?android:attr/textAppearanceMedium"

android:text="经济型酒店分体空调解决方案"

android:textColor="@color/colorTextWhite"

android:layout_gravity="center"

android:id="@+id/tv_show_industry_list_title" />

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:textAppearance="?android:attr/textAppearanceMedium"

android:text="广泛应用于住宅地产、宿舍、教学楼、通讯基站等,为其打造舒适空气解决方案"

android:id="@+id/tv_show_industry_list_detail"

android:layout_margin="20dp"

android:textSize="@dimen/font_size_30"

android:textColor="@color/colorTextGray" />

android:layout_width="120dp"

android:layout_height="35dp"

android:text="查看详情"

android:id="@+id/bt_show_industry_list_cat"

android:textColor="@color/colorTextWhite"

android:layout_gravity="center_horizontal"

android:background="@drawable/drawable_circle_corner" />

主布局类ShowIndustryListActivity.java

public class ShowIndustryListActivity extends BaseActivity {

private FragmentPagerAdapter pagerada;

private ShowIndustryListFragment showIndustryListFragment;

ShowIndustryListFragment fragment1,fragment2,fragment3,fragment4;

ArrayList fragments;

@Bind(R.id.vp_show_industry_list)

ViewPager viewPager;

FragmentManager fragmentManager;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_show_industry_list);

ButterKnife.bind(this);

fragmentManager = getSupportFragmentManager();

fragments= new ArrayList();

fragment1 = new ShowIndustryListFragment();

fragment2 = new ShowIndustryListFragment();

fragment3 = new ShowIndustryListFragment();

fragment4 = new ShowIndustryListFragment();

fragments.add(fragment1);

fragments.add(fragment2);

fragments.add(fragment3);

fragments.add(fragment4);

viewPager.setOffscreenPageLimit(fragments.size());//卡片数量

viewPager.setPageMargin(10);//两个卡片之间的距离,单位dp

if (viewPager!=null){

viewPager.removeAllViews();

}

MyFragmentPagerAdapter myFragmentPagerAdapter = new MyFragmentPagerAdapter(getSupportFragmentManager(), fragments);

viewPager.setAdapter(myFragmentPagerAdapter);

}

class MyFragmentPagerAdapter extends FragmentPagerAdapter {

private ArrayList listFragments;

public MyFragmentPagerAdapter(FragmentManager fm, ArrayList al) {

super(fm);

listFragments = al;

}

public MyFragmentPagerAdapter(FragmentManager fm) {

super(fm);

}

@Override

public Fragment getItem(int position) {

return listFragments.get(position);

}

@Override

public int getCount() {

return listFragments.size();

}

@Override

public int getItemPosition(Object object) {

return super.getItemPosition(object);

}

}

}

至此,效果就可以实现了,上手试试吧。

更多关于滑动功能的文章,请点击专题: 《Android滑动功能》

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持亿速云。

Android横向滚动卡片,Android实现横向滑动卡片效果相关推荐

  1. vue实现简单的鼠标拖拽横向滚动和 鼠标滚轮横向滚动

    原文地址:vue实现简单的鼠标拖拽横向滚动和 鼠标滚轮横向滚动_超人不会飞啊的博客-CSDN博客_vue鼠标拖拽 这边如果是动态渲染的div,需要等dom渲染结束后.id存在了.再去设置this.sc ...

  2. android fragment界面滑动切换效果,Android App中使用ViewPager+Fragment实现滑动切换效果...

    在android应用中,多屏滑动是一种很常见的风格,没有采用viewpager的代码实现会很长,如果采用ViewPager,代码就会短很多,但是使用ViewPager也有弊端:需要导入android- ...

  3. android 横向滚动图片,Android使用Photoview实现图片左右滑动及缩放功能

    Android使用Photoview实现图片左右滑动及缩放功能 发布时间:2020-10-12 14:51:12 来源:脚本之家 阅读:119 作者:kuaizilanqiu 我想,不管是做什么样的a ...

  4. Android 横向滚动列表 (类似横向ListView)

    示例: 布局代码***.xml: <?xml version="1.0" encoding="utf-8"?> <LinearLayout x ...

  5. android自定义滚动日期,Android基于wheelView实现自定义日期选择器

    本文实例为大家分享了Android实现自定义日期选择器的具体代码,供大家参考,具体内容如下 项目要求效果图: 要求 "6月20 星期五" 这一项作为一个整体可以滑动,"7 ...

  6. Android 高仿华为手机Tab页滑动导航效果

    首先带大家看一下实现效果,用了两种实现方式: 1.基于LinearLayout实现,导航栏不可响应手指滑动 2.基于HorizontalScrollView实现,导航栏可响应手指滑动 实现方式虽然不一 ...

  7. html页面加文字横向滚动,js实现文字横向滚动

    页面布局 恭喜793765***获得 50元巨人点卡奖励 恭喜793765***获得 50元巨人点卡奖励 恭喜793765***获得 50元巨人点卡奖励 恭喜793765***获得 50元巨人点卡奖励 ...

  8. android循环滚动textview,Android 循环上下滚动

    最近在做项目的时候遇到了一个上下滚动文字的需求,在网上找到了一个自定义的TextView,但是切换效果很图片,没有滚动的效果,考虑到html的marquee效果添加到TextView中,无奈没有效果, ...

  9. android 文字滚动组件,Android textview 跑马灯文字滚动效果

    设置如下TextView控件文件的XML: android:id="@+id/textview" android:layout_width="match_parent&q ...

  10. android数字滚动动画,Android超简单实现金钱滚动效果

    目录 目录 效果展示 实现原理 利用ValueAnimator将数值从0一直增长到你所需要展示的数值,然后使用TextView将增长过程中的数值不断展示即可实现金钱的滚动效果. ValueAnimat ...

最新文章

  1. mysql表分区占用存储_MySQL 分区分表应用场景分析和分区中可能遇到的坑点
  2. java排序为什么会出现多次排序结果不一样_并发理论基础:指令重排序问题
  3. UA MATH567 高维统计 专题0 为什么需要高维统计理论?——以线性判别分析为例
  4. opencv镜像_DX200操作要领—PAM与镜像平移变换(三十八)
  5. 打开windows 10系统语言设置的快捷方式
  6. PDC Party 即将在东莞登场
  7. @Builder 实际参数列表和形式参数列表长度不同
  8. 程序员的恶性循环:加班-没空学习-老是写同等水平代码-无法提升代码质量-老是出BUG-老是需要修改-加班-......
  9. 如何运营批量推特账户
  10. 刷新率属于计算机的显示性能指标吗,显示器性能指标(菜鸟必看)
  11. 浅析微信支付:支付结果通知
  12. 选下拉框的的值对应上传相应的图片_excel表格下拉菜单调用对应数据,如何在excel中实现,选择下拉菜单某一项,该表格中就出现选项对应的数据?...
  13. 保健中药不贵胜过市面上的保健品
  14. Spark SQL实战(08)-整合Hive
  15. 宇视摄像机码流类型定码率和变码率的区别?
  16. Jenkins Pipelin扩展
  17. FIR数字滤波器的FPGA实现(二)-串行FIR滤波器设计(1)
  18. 柳州植物组织培养实验室建设施工意义
  19. 微信聊天记录制作词云图
  20. 用户购买CD消费行为分析

热门文章

  1. 在公司拿了奖,发了点奖金
  2. php安卓直播抓取,hls,android_安卓大部分浏览器播放HLS协议直播流会从头开始,hls,android,ffmpeg,m3u8 - phpStudy...
  3. php更多式样,php_1
  4. 推荐一本学习生信的好书,新手友好,实战性强
  5. 【NGS接龙】薛宇:漫谈生物信息圈儿的那些年、那些事!
  6. Astro Panel Pro for Mac - ps天文景观插件 支持ps2021
  7. FCPX插件:科幻切割分屏转场效果XEffects Tech Transitions mac版
  8. 如何在 Mac 上将 JPG图像合并为一个PDF
  9. 哪些是MySQL用于放置一些头文件的目录_在古希腊的知识体系中,两大部分是( )。...
  10. oracle 天转换成月函数_oracle 日期转换格式 函数