Android:为设置NestedScrollView的最大高度而创建的自定义类不起作用(没有滚动条)
创始人
2024-10-13 20:01:27
0

要为NestedScrollView设置最大高度并且显示滚动条,可以尝试以下解决方法:

  1. 创建一个自定义类MaxHeightNestedScrollView,继承NestedScrollView类。
public class MaxHeightNestedScrollView extends NestedScrollView {

    private int maxHeight;

    public MaxHeightNestedScrollView(Context context) {
        super(context);
    }

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

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

    public void setMaxHeight(int maxHeight) {
        this.maxHeight = maxHeight;
    }
    
    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        int heightMode = MeasureSpec.getMode(heightMeasureSpec);
        int heightSize = MeasureSpec.getSize(heightMeasureSpec);
        int maxHeightMeasureSpec = MeasureSpec.makeMeasureSpec(maxHeight, heightMode);
        super.onMeasure(widthMeasureSpec, maxHeightMeasureSpec);
    }
}
  1. 在布局文件中使用自定义的MaxHeightNestedScrollView,并设置最大高度和滚动条。


    


这样,设置了最大高度的NestedScrollView将显示滚动条,并在内容超过最大高度时进行滚动。

相关内容

热门资讯

今日公布!hhpoker是正品... 今日公布!hhpoker是正品吗,红龙poker辅助工具,教你攻略(有挂技巧)科技教程也叫必备教程,...
推荐攻略!红龙poker辅助平... 推荐攻略!红龙poker辅助平台,wepoker怎么设置透视,解密教程(有挂神器)科技教程也叫必备教...
玩家必备攻略!aapoker ... 玩家必备攻略!aapoker ai插件,红龙poker辅助工具,切实教程(有挂技巧)科技教程也叫必备...
玩家必看教程!werplan有... 自定义wepoker俱乐部辅助系统规律,只需要输入自己想要的开挂功能,一键便可以生成出微扑克专用辅助...
重大通报!wepoker透视有... 重大通报!wepoker透视有吗,wepoker透视脚本网页,必赢教程(有挂教程)1、玩家可以在we...
我来分享!impoker辅助,... 我来分享!impoker辅助,uupoker透视,实用技巧(有挂透视);原来确实真的有挂(需添加指定...
一分钟了解!sohoo开挂辅助... 一分钟了解!sohoo开挂辅助,wepoker透视功能下载,黑科技教程(有挂技巧);玩家必备必赢加哟...
揭秘攻略!pokemmo脚本,... 您好,pokemmo脚本这款游戏可以开挂的,确实是有挂的,需要了解加微【136704302】很多玩家...
一分钟带你了解!hhpoker... 一分钟带你了解!hhpoker真能买到挂吗,德州来玩辅助器,解说技巧(有挂教程);实战中需综合运用上...
我来教大家!xpoker辅助怎... 我来教大家!xpoker辅助怎么用,werplan辅助软件,细节揭秘(有挂技巧);人气非常高,ai更...