How can I set attribute onClick to a ScrollView?

喜你入骨 提交于 2019-12-06 15:01:22

You could try to let the LinearLayout implement the onClick attribute and then set:

android:fillViewport="true"

to the ScrollView.

I had a similar issue, and simply got rid of the scrollview itself. Instead, I directly inserted the TextView itself, with the constraints previously put on the ScrollView. The whole purpose of my ScrollView was to scroll in the TextView, not among several items, so it seemed a more elegant way to do.

Add a (vertical) scrollbar to my textview in activity.hmtl :

    <TextView
    android:id="@+id/tvInfo"
    (...) 
    android:scrollbars="vertical" 
    />

Add this to the onCreate method:

    oTV = (TextView) findViewById(R.id.tvInfo);
    oTV.setMovementMethod(new ScrollingMovementMethod());

No need to write the scrolling response. I like that.

I found the solution here (thx Juned Mughal) :

http://www.android-examples.com/make-textview-scrollable-in-android-programmatically/

To make the scroll view fill the screen change:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/white" >

to

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@android:color/white" >

and for the click put this in your onCreate method:

((ScrollView) findViewById(R.id.scrollView))
                .setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        toQuestion();
                    }
                });
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!