Android开发之解决ListView和ScrollView滑动冲突的问题

nnDetection复现Luna16肺结节检测基线实战指南 肺结节检测是医学影像AI落地的核心任务之一,其本质属于三维目标检测问题,依赖精确的体素级定位与小目标敏感建模。技术原理上需兼顾各向异性CT重采样、世界坐标系转换、3D滑动窗口推理及临床导向的FROC评估。nnDetection框架凭借PyTorch原生实现与专为医学影像优化的pipeline,在可复现性、可调试性与部署稳定性方面具备显著工程优势;Luna16数据集则提供经多医生共识标注的低剂量CT基准,是验证模型临床可信度的关键标尺。结合cuda11.4与cudnn8.2.4这一稳定生产环境组合,可有效规避 阅读详情

最近在项目中遇到了如下问题:ScrollView中嵌套2个ListView。当滑动ScrollView的时候,ListView的显示只有1-2个item的问题。上网查过之后,一些解决方案,比如强行设置ListView的高度,还有一些设置ScrollView的监听等方法。不能够解决我的问题。后来还是总结出了两套解决方案。

方案一:自定义ListView,重写onMeasure()方法。

代码如下:

public class MyListView extends ListView {
    public MyListView(Context context) {
        super(context);
    }

    public MyListView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public MyListView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        heightMeasureSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE>>2,MeasureSpec.AT_MOST);
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }
}

在onMeasure方法中,指定ListView的高度。


方案二:创建如下方法并调用。

/**
     * 解决ScrollView和ListView滑动冲突的问题,让ListView随着ScrollView一起滑动。
     * */
    public static void setListViewHeightBasedOnChildren(ListView listView) {
        ListAdapter listAdapter = listView.getAdapter();
        if (listAdapter == null) {
            return;
        }

        int totalHeight = 0;
        for (int i = 0; i < listAdapter.getCount(); i++) {
            View listItem = listAdapter.getView(i, null, listView);
            listItem.measure(0, View.MeasureSpec.makeMeasureSpec(0,
                    View.MeasureSpec.UNSPECIFIED));
            totalHeight += listItem.getMeasuredHeight();
        }

        ViewGroup.LayoutParams params = listView.getLayoutParams();
        params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
        listView.setLayoutParams(params);
    }


Android ListView与ScrollView冲突的解决方法总结 Android ListView与ScrollView冲突的解决方法总结 众所周知ListView与ScrollView都具有滚动能力,对于这样的View控件,当ScrollView与ListView相互嵌套会成为一种问题:  问题一:ScrollView与ListView嵌套导致ListView显示不全面  问题二:ScrollView不能正常滑动 解决方式一: ScrollView+LinearLayout+ListView可以换成ScrollView+LinearLayout+LinearLayout,对于开发中,ScrollView所能滚动的样式形式各异,另外的话,ScrollView 立即下载

相关推荐

安卓集成华为HMS Scankit实现自定义扫码功能

实现扫码功能 使用的是集成华为扫描的SDK,UI界面借鉴的是谷歌官方的Zxing项目中的自定义view,两者结合实现。 先上效果图: 先在项目根级别(build.gradle)当中配置HMS Core SDK的Maven仓地址。 // 配置HMS Core SDK的Maven仓地址。 maven {url 'https://developer.huawei.com/repo/'} // 配置HMS Core SDK的Maven仓地址。 maven {url 'https://developer.huaw

qq_47625961的博客 5512

解决重写onMeasure 解决ListView 与ScrollView嵌套时 listView自动回弹问题

方法1.自定义一个类继承自ListView,通过重写其onMeasure方法,达到对ScrollView适配的效果。

sta_y的专栏 541

Intel SGX Explained

计算机中最主要的资源是CPU和内存,由操作系统和虚拟管理系统等系统软件来管理这些资源。

hanqdi_的博客 3455

android 自定义listview不能滑动,android 自定义listView,重写onMeasure,无法上下滑动...

本人想实现相似下图的功能。自定义listView代码如下:publicclassMyListViewextendsListView{publicMyListView(Contextcontext,AttributeSetattrs){super(context,attrs);}publicMyListView(Contextcontext){super(context)...

weixin_42348783的博客 544

无监督低照度增强实战:用ZeroDCE和SCI拯救你的夜间照片(附PyTorch代码)

本文深入探讨了无监督低照度图像增强技术,重点解析了ZeroDCE和SCI两大代表性模型的核心原理与实战应用。通过对比分析两者的技术路径、网络结构及性能特点,并附上详细的PyTorch代码实现,旨在帮助读者掌握无需配对数据即可有效提升夜间照片画质的深度学习解决方案。

git9versioner的博客 489

别再乱选离散化方法了!从零到一用Matlab对比差分、双线性Tustin和预矫正的实战效果

本文深入探讨了Matlab中四种主流离散化方法(差分、双线性Tustin和预矫正)的实战效果对比,帮助工程师在数字控制系统设计中做出明智选择。通过详细的理论分析和Matlab代码示例,展示了不同方法在稳定性、频率响应和计算复杂度上的差异,并提供了针对不同场景的工程选用指南。

weixin_28737603的博客 141

android listview onmeasure,android自定義控件(一)MeasureSpec 與 ListView.onMeasure

A MeasureSpec encapsulates the layout requirements passed from parent to child. Each MeasureSpec represents a requirementfor either the width or the height. A MeasureSpec is comprised of a size and a ...

weixin_42547431的博客 211

告别抖动与滞后:深入博能传动伺服DSC功能,用105报文提升多轴同步性能

本文深入解析博能传动伺服DSC功能如何通过105报文实现多轴同步性能提升,有效解决工业自动化中的抖动与滞后问题。详细介绍了DSC技术原理、105报文实现机制及多轴同步工程实践,帮助工程师优化伺服系统性能,实现绝对齿轮同步。

weixin_30394981的博客 184

【进阶android】ListView源码分析——布局三大方法

视图从初始化到完全展示到屏幕之上,这段时间里,还有许多工作要做;总体而言,这些工作可用分为三大步骤;而这三大步骤便是View类的三大布局方法onMeasure、onLayout以及onDraw,三个方法分别表示对视图进行测量、布局及绘制。     ListView是一个视图,当然也会重写这三个主要的方法;同时,这三个方法也完成了ListView在展示到屏幕之前,所需要完成的绝大多数初始化工作。

一张杭州票的专栏 1102

【从零开始学习SLAM】官方tf教程小海龟跟随程序

ros tf 进行坐标系之间转换的运算和发布

小秋 AI SLAM 入门实战教程 2033

逆强化学习:从专家示范中学习策略

逆强化学习(Inverse Reinforcement Learning,简称IRL)是强化学习(Reinforcement Learning,简称RL)的一个子领域,它的目标是从专家的行为中学习策略。在传统的强化学习中,智能体通过与环境交互,根据奖励信号来学习一个策略。而在逆强化学习中,我们没有直接的奖励信号,而是通过观察专家的行为来推断出奖励函数,从而学习到一个与专家类似的策略。逆强化学习作为强化学习的一个重要子领域,在许多实际应用场景中都取得了显著的成功。

AI天才研究院 1450

android 自定义View学习一之onMeasure和onLayout

本文主要作为一个回忆笔记存在,不是从一开始的源码研究,所以是一个结论笔记。 通常来说我们创建一个activity的布局层次:

qq_34606099的博客 2089

[Dify实战]插件编写- 如何让插件直接输出文件对象(支持 TXT、Excel 等)

本文介绍了在Dify插件中实现文件对象返回的方法。通过create_blob_message()函数,开发者可以输出txt、Excel等格式文件,让用户直接下载而非复制文本。文章详细讲解了二进制文件生成的原理,提供了文本翻译和Excel报表生成的代码示例,并列出常见MIME类型对照表。这种技术能显著提升插件实用性,特别适用于翻译、报表生成等需要文件输出的场景,使交互体验从"复制粘贴"升级为"一键下载"。

技术小甜甜:传播可落地技术,帮助个人和企业降低解决真实场景问题的成本 1247

Android实践之ScrollView中滑动冲突处理

在Android开发中,如果是一些简单的布局,都很容易搞定,但是一旦涉及到复杂的页面,特别是为了兼容小屏手机而使用了ScrollView以后,就会出现很多点击事件的冲突,最经典的就是ScrollView中嵌套了ListView。我想大部分刚开始接触Android的同学们都踩到过这个坑,这一篇文章就从最近做的一个项目讲起,然后在过程中提供一些解决冲突的思路。

王三的专栏 2万+

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

ScrollView 与 ListView 以及 GridView 滑动冲突完美解决

2019独角兽企业重金招聘Python工程师标准>>> ...

weixin_34176694的博客 287

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Android中Scrollview、ViewPager冲突问题汇总(已解决)

显示问题: 1、设置ScrollView的fillViewPort为true 2、设置ViewPager的layout_height为一个固定高度,比如:100dip   冲突问题: 不过ViewPager显示出来以后,还有另外一个冲突:ViewPager左右不能滑动了!是的,因为这个事件其实已经被外层的ScrollView截获! 重写ScrollView控件! 0、http://m

mcy478643968的专栏 3万+

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

浅谈ScrollView嵌套ListView及ListView嵌套的高度计算

引言   在Android开发中,我们有时会需要使用ScrollView中嵌套ListView的需求。例如:在展示信息的ListView上还有一部分信息展示区域,并且要求这部分信息展示区域在ListView信息比较多的时候也是可以滑动的,而不是固定不变的。这时,我们一般会将ScrollView和ListView嵌套在一起使用。但是这会导致ListView展示不全,然后也会有滑动冲突问题...

diezhi2505的博客 156

Scrollview总结:滑动问题、监听Scrollview实现头部局改变

ScrollView就是一个可以滚动的View,这个滚动的方向是垂直方向的,而HorizontalScrollView则是一个水平方向的可以滚动的View。 ScrollView的简单介绍 ScrollView和HorizontalScrollView只是两种滚动方向不同的View而已,其他方面都基本相同,所以下面只单单以ScrollView来介绍。 ScrollView必须有一个...

160

ScrollView嵌套ListView只显示一行和ScrollView嵌套RecyclerView

在开发的过程当中,由于手机屏幕的大小的限制,我们经常需要使用滑动的方式,来显示更多的内容。在最近的工作中,遇见一个需求,需要将ListView嵌套到ScrollView中显示。于是乎有了如下布局: &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://............

扣子Coze大师班 1100

解决Android 中那些嵌套滑动事件冲突问题--合集

滑动冲突,就其本质来说,两个不同方向(或者是同方向)的View,其中有一个是占主导地位的,每次总是抢着去处理外界的滑动行为,这样就导致一种很别扭的用户体验,明明只是横向的滑动了一下,纵向的列表却在垂直方向发生了动作。就是说,这个占主导地位的View,每一次都身不由己的拦截了这个滑动的动作,因此,要解决滑动冲突,就是得明确告诉这个占主导地位的View,什么时候你该拦截,什么时候你不应该拦截,应该由下一层的View去处理

Checkiming的博客 2011

ViewPager,ScrollView 嵌套ViewPager滑动冲突解决

总之啊,家里没矿的同学们,如果你们想以后的日子过得好一些,多想想你们的业余时间怎么安排吧;技术方面的提升肯定是重中之重,但是技术外的一些“软实力”也不能完全忽视,很多时候升职确实是因为你的技术足够强,但也与你的“软实力”密切相关在这我也分享一份大佬自己收录整理的Android学习PDF+架构视频+面试文档+源码笔记,还有高级架构技术进阶脑图、Android开发面试专题资料,高级进阶架构资料这些都是我闲暇还会反复翻阅并给下属员工学习的精品资料。

2401_84008985的博客 1127

scrollview嵌套listview产生的滑动冲突(recyclerview)

Android滑动冲突主要有两种方法: 1、外部拦截法 public class ListScrollView extends ScrollView {              private ListView listView;          public ListScrollView(Context context, AttributeSet attrs) {

yancychas的博客 1万+

ScrollView与ListView(ExpandableListView)的滑动冲突解决方法

在Android开发中,如果外层使用ScrollView嵌套ListView(ExpandableListView),以下统一称为ListView,会导致ListView的显示高度变窄,甚至不能实现屏幕外内容的括展,那么滑动冲突就出现了。 解决思路: 思路一: 在XML中将高度固定(如果ListView中的item不够多,或者要显示的内容没有超出屏幕可以使用) 在代码中将高度固定,如下所示...

fly_Xiaoma的博客 1265

解决ScrollView和GridListView和ListView滑动冲突方法(二)自定义ListView和GridView

效果 直接上代码 主布局<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="

段炼 852

androidUI(ScrollView与GridView,ListView的冲突)

问题: android开发时候需要ScrollView嵌套时候GridView,ListView只剩下一行显示。 滑动事件冲突 解决方案: 自定义 ListView,GridView,不生成滑动条。 具体如下: 1、自定义View继承GridView。 2、重写onMeasure方法,不生成滑动。 public class MyGridView ex

android小菜 640
上一篇: Android开发之实现简单的极光推送
下一篇: android开发之解决PopWindow中EditText无法复制粘贴问题
红鼻子老头
博客等级 码龄10年 10粉丝 13原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值