如何在Android应用中使用ScrollView实现悬浮效果

  介绍

如何在Android应用中使用ScrollView实现悬浮效果?针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。

新建一个Android项目,

& lt;及# 63;xml version=?.0”;编码=癠TF-8", # 63;比;   http://schemas.android.com/apk/res/android" & lt; LinearLayout xmlns: android=?;   android:取向=癶orizontal"   android: layout_width=癴ill_parent"   android: layout_height=皐rap_content"比;      & lt; ImageView   android: id=癅 + id/buy_layout"   android: layout_width=癴ill_parent"   android: layout_height=皐rap_content"   android:背景=癅drawable/buy"/比;      & lt;/LinearLayout>   

立即抢购的布局实现了,接下来实现主界面的布局,上面是导航栏布的局,为了方便还是直接从美团截取的图片,然后下面的:viewpage布的局,立即抢购布的局,其他布局放在滚动视图里面,界面还是很简单的

& lt; LinearLayout xmlns: android=癶ttp://schemas.android.com/apk/res/android"   xmlns:工具=癶ttp://schemas.android.com/tools"   android: layout_width=癿atch_parent"   android: layout_height=癿atch_parent"   android:取向=皏ertical"比;      & lt; ImageView   android: id=癅 + id/imageView1"   android: scaleType=癱enterCrop"   android: layout_width=癿atch_parent"   android: layout_height=?5 dip"   android: src=https://www.yisu.com/zixun/" @drawable/navigation_bar "/>                     <包括   android: id=癅 + id/购买”   布局=" @layout/buy_layout "/>                     LinearLayout         LinearLayout   

你会发现上面的主界面布局中并不是滚动视图,而是自定义的一个MyScrollView,接下来就看看MyScrollView类中的代码

包com.example.meituandemo;
  
  进口android.content.Context;
  进口handler;
  进口android.util.AttributeSet;
  进口android.view.MotionEvent;
  进口android.widget.ScrollView;/* *
  *博客地址:http://blog.csdn.net/xiaanming
  *
  * @author xiaanming
  *
  */公开课MyScrollView延伸ScrollView {
  私人com.example.meituandemo>包;
  
  进口android.app.Activity;
  进口android.content.Context;
  进口android.graphics.PixelFormat;
  进口android.os.Bundle;
  进口android.view.Gravity;
  进口android.view.LayoutInflater;
  进口android.view.View;
  进口android.view.WindowManager;
  进口android.view.WindowManager.LayoutParams;
  进口android.widget.LinearLayout;
  进口com.example.meituandemo.MyScrollView.OnScrollListener;/* *
  *博客地址:http://blog.csdn.net/xiaanming
  *
  * @author xiaanming
  *
  */公共类MainActivity扩展活动实现>关于如何在Android应用中使用ScrollView实现悬浮效果问题的解答就分享到这里了,希望以上内容可以对大家有一定的帮助,如果你还有很多疑惑没有解开,可以关注行业资讯频道了解更多相关知识。

如何在Android应用中使用ScrollView实现悬浮效果