如何以编程方式在NestedScrollView中显示滚动条。

问题描述 投票:3回答:2
NestedScrollView nestedScrollView  = (NestedScrollView) findViewById(R.id.content);
nestedScrollView.setVerticalScrollBarEnabled(true);

setVerticalScrollBarEnabled没有在上面的代码中工作。

android android-layout android-widget android-scrollview android-nestedscrollview
2个回答
2
投票

有两种方式:

来自Java代码:NesteadScrollView.setScrollbarFadingEnabled(true);

来自XML代码:android:fadeScrollbars="true"

就那么简单!


0
投票

经过一些研究发现这个问题的解决方法。在android sdk视图级别滚动从xml属性调用。执行以下步骤。

步骤1:使用android:scrollbars="vertical"创建一个xml文件并将其放在xml文件夹中(在res create xml文件夹中并放置文件)

<?xml version="1.0" encoding="utf-8"?>
    <android.support.v4.widget.NestedScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:scrollbars="vertical"/>

步骤2:在Java文件中,添加以下代码段

NestedScrollView nestedScrollView  = new NestedScrollView(getBaseContext(),getAttributeSet());

private AttributeSet getAttributeSet() {
        AttributeSet attr = null;
        try {
            XmlPullParser parser = getResources().getXml(R.xml.xml);
            try {
                parser.next();
                parser.nextTag();
            } catch (Exception e) {
                e.printStackTrace();
            }

            attr = Xml.asAttributeSet(parser);
            return attr;
        } catch (Exception e) {
            return attr;
        }
    }
© www.soinside.com 2019 - 2024. All rights reserved.