最近在项目中,产品经理看见uc浏览器首页的上拉面板的效果做的非常不错,于是希望我们的项目的首页也做成这样的效果。于是经过思考后,实现了一个仿uc浏览器的上拉面板效果。

接下来说一下实现的思路吧 。
首先这个上拉的效果在github上有一个开源的项目。可以拿来使用。链接地址
下面是布局xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"tools:context="com.example.myapplication.MainActivity"><com.sothree.slidinguppanel.SlidingUpPanelLayout xmlns:sothree="http://schemas.android.com/apk/res-auto"android:id="@+id/sliding_layout"android:layout_width="match_parent"android:layout_height="match_parent"android:gravity="bottom"sothree:umanoDragView="@+id/ll_panl"sothree:umanoPanelHeight="168dp"sothree:umanoScrollableView="@+id/content_view"sothree:umanoShadowHeight="4dp"><TextView
            android:id="@+id/tv_main"android:layout_width="match_parent"android:layout_height="match_parent"android:gravity="center"android:text="Main Content"android:textSize="16sp" /><LinearLayout
            android:id="@+id/ll_panl"android:layout_width="match_parent"android:layout_height="match_parent"android:gravity="center|top"android:orientation="vertical"><com.example.myapplication.refresh.PullToRefreshLayout
                android:id="@+id/refresh_view"android:layout_width="match_parent"android:layout_height="match_parent"><include layout="@layout/refresh_head" /><!-- 支持所有实现Pullable接口的View --><com.example.myapplication.refresh.PullableListView
                    android:id="@+id/content_view"android:layout_width="match_parent"android:layout_height="match_parent"android:background="@color/white"android:divider="@color/gray"android:dividerHeight="1dp" /><include layout="@layout/load_more" /></com.example.myapplication.refresh.PullToRefreshLayout></LinearLayout></com.sothree.slidinguppanel.SlidingUpPanelLayout>
</LinearLayout>

注意一点是面板的布局里面只能有两个孩子,不然会报异常
但是如果你想在下面的面板中放一个listview的话就会有滑动冲突,因为listview需要滑动,上拉面板也需要滑动。遇见冲突当然就要解决了,在仔细观察uc的效果后,终于有了思路了。下面的listview已经不是一个传统的listview了。这时候我们可以引入带下拉刷新的listview。说到这也许大家应该明白差不多了。意思是,我们可以监听面板的状态,在面板拉上去时就禁止面板的滑动。这时候面板要想下拉就可以在listview中监听了,因为下拉刷新的listview有一个下拉的动作。如果在listview中监听到有下拉的动作就让面板下去。
下面看一下具体的代码实现:

package com.example.myapplication;import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ListView;
import android.widget.TextView;import com.example.myapplication.refresh.PullToRefreshLayout;
import com.sothree.slidinguppanel.SlidingUpPanelLayout;import java.util.ArrayList;
import java.util.List;public class MainActivity extends AppCompatActivity {private ListView listView;private PullToRefreshLayout ptrl;private TextView mainTV;/*** 上拉面板的布局*/private SlidingUpPanelLayout slidingUpPanelLayout;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);slidingUpPanelLayout = (SlidingUpPanelLayout) findViewById(R.id.sliding_layout);ptrl = ((PullToRefreshLayout) findViewById(R.id.refresh_view));listView = (ListView) findViewById(R.id.content_view);mainTV = (TextView) findViewById(R.id.tv_main);initListView();ptrl.setOnRefreshListener(new PullToRefreshLayout.OnRefreshListener() {@Overridepublic void onRefresh(final PullToRefreshLayout pullToRefreshLayout) {//监听面板的下拉slidingUpPanelLayout.setPanelState(SlidingUpPanelLayout.PanelState.COLLAPSED);pullToRefreshLayout.refreshFinish(PullToRefreshLayout.SUCCEED);}@Overridepublic void onLoadMore(PullToRefreshLayout pullToRefreshLayout) {}});slidingUpPanelLayout.addPanelSlideListener(new SlidingUpPanelLayout.PanelSlideListener() {//当滑动面板的位置变化调用@Overridepublic void onPanelSlide(View panel, float slideOffset) {//上面面板的缩放的效果mainTV.setScaleX(1 - slideOffset + 0.7F * slideOffset);mainTV.setScaleY(1 - slideOffset + 0.7F * slideOffset);}@Overridepublic void onPanelStateChanged(View panel, SlidingUpPanelLayout.PanelState previousState, SlidingUpPanelLayout.PanelState newState) {//监听面板上拉if (newState == SlidingUpPanelLayout.PanelState.EXPANDED) {slidingUpPanelLayout.setTouchEnabled(false);listView.setEnabled(true);}else if(newState == SlidingUpPanelLayout.PanelState.COLLAPSED){slidingUpPanelLayout.setTouchEnabled(true);listView.setEnabled(false);}else if(newState == SlidingUpPanelLayout.PanelState.ANCHORED){slidingUpPanelLayout.setPanelState(SlidingUpPanelLayout.PanelState.COLLAPSED);listView.setEnabled(false);}}});}/*** ListView初始化方法*/private void initListView() {List<String> items = new ArrayList<String>();for (int i = 0; i < 30; i++) {items.add("这里是item " + i);}MyAdapter adapter = new MyAdapter(this, items);listView.setAdapter(adapter);}
}

就这样一个高仿uc浏览器的上拉面板效果就实现了,喜欢就点个赞吧

源码下载

android 高仿UC浏览器首页上拉面板效果相关推荐

  1. android 360状态栏显示,Android高仿UC浏览器和360手机卫士消息常驻栏(通知栏)

    之前网上看了下自定义消息栏,通知栏,了解到了Notification这个控件,发现UC浏览器等都是这种类型,今天写个demo实现下,如图: 其中每个按钮都有不同的功能,代码如下: package co ...

  2. android获取通知栏消息源代码,Android高仿UC浏览器和360手机卫士消息常驻栏(通知栏)(示例代码)...

    之前网上看了下自己定义消息栏,通知栏,了解到了Notification这个控件.发现UC浏览器等都是这样的类型,今天写个demo实现下.如图: 当中每一个button都有不同的功能.代码例如以下: p ...

  3. 一款非常不错的高仿UC浏览器源码下载

    今天给大家分享一款非常不错的android源码,这是我刚刚在网上找到的源码,高仿UC浏览器源码下载,希望大家能够喜欢. 源码下载: http://code.662p.com/view/1634.htm ...

  4. android高仿微信聊天页面,Android 高仿微信语音聊天页面高斯模糊(毛玻璃效果)

    目前的应用市场上,使用毛玻璃效果的APP随处可见,比如用过微信语音聊天的人可以发现,语音聊天页面就使用了高斯模糊效果. 先看下效果图: 仔细观察上图,我们可以发现,背景图以用户头像为模板,对其进行了高 ...

  5. android项目uc浏览器,Android项目仿UC浏览器和360手机卫士消息常驻栏(通知栏)

    之前网上看了下自定义消息栏,通知栏,了解到了Notification这个控件,发现UC浏览器等都是这种类型,今天写个demo实现下,如图: 其中每个按钮都有不同的功能,代码如下: package co ...

  6. android 微信高仿,Android 高仿微信发朋友圈浏览图片效果(转)

    最近一直在高仿微信.高仿微信,今天小编再给大家分享一个仿微信发朋友圈浏览图片的效果.... 好了,先看一下效果吧: 这里写图片描述 下面就来说一下具体怎么实现的: 实现思路 1.首先我们要获取数据源, ...

  7. Android 高仿微信发朋友圈浏览图片效果

    最近一直在高仿微信.高仿微信,今天小编再给大家分享一个仿微信发朋友圈浏览图片的效果.... 好了,先看一下效果吧: 下面就来说一下具体怎么实现的: 实现思路 1.首先我们要获取数据源,数据源就是我们的 ...

  8. 高仿知乎android,Android高仿知乎首页Behavior

    Android自定义Behavior实现跟随手势滑动,显示隐藏标题栏.底部导航栏及悬浮按钮 Android Design包下的CoordinatorLayout是相当重要的一个控件,它让许多动画的实现 ...

  9. Android高仿京东、天猫下拉刷新

    说到下拉刷新,相信大家都不陌生,现在基本上每个项目都会用到.我们公司的项目一直都是使用SwipeRefreshLayout,官方的Material Design风格,好用少Bug.现在下拉刷新大概有下 ...

最新文章

  1. Android 唯一标识获取
  2. matlab中线性规划优化计算方法和实例
  3. 经典笔试题: 二叉树中和为某一值的路径(路径总和)
  4. php switch 函数,PHP丨PHP基础知识之条件语SWITCH判断「理论篇」
  5. Spring+Quartz 集群
  6. c语言循环8,C语言8 循环语句 | CN-SEC 中文网
  7. android 自定义取色器,【Android自定义View】仿Photoshop取色器ColorPicker(二)
  8. jquery validate常用方法及注意问题
  9. 用ABAP代码实现从1累加到100
  10. android studio导入eclipse项目各种问题,Android | 导入Eclipse项目到Android studio的问题解决全过程...
  11. MySQL的错误:No query specified
  12. python一加到二十等于多少_Python 3.1新变化之性能改善篇(转载)
  13. nodejs实践录:ubuntu 16.04系统nodejs环境搭建
  14. SpringCloud学习笔记027---SpringBoot集成MyBatis_实现多数据源_可以自定义数据库类型
  15. 关于JS的window.onload与$(function (){})方法区别
  16. Java - 单例模式
  17. solidworks流体模拟分析概述
  18. 小米路由器怎么设置无盘服务器,小米路由器怎么设置?
  19. 计算机中cpu是指什么意思,CPU是什么?CPU又是什么意思?
  20. PHP反序列化-__wakeup()方法漏洞(CVE-2016-7124)

热门文章

  1. 程序员必须学会的谷歌搜索技巧
  2. 最近使用网络电话,还比较便宜
  3. 【笔记】路由器 - 软硬件构成
  4. 【MACOS】macbook pro使用感受
  5. CG动画制作项目第一篇:剧本的编写,前期工作的敲定
  6. 转为什么收入越来越少?--一切看起来都很美好
  7. ProcessDB实时/时序数据库——JDBC读写实时数据
  8. android加载字体内存泄露,在Windows GDI中创建和使用字体/避免内存泄漏
  9. 双显示器 启动黑屏 黑苹果_黑苹果装机黑屏问题解决方案5500xt
  10. Slicer学习笔记(四十六)slicer 常用的几个模块