T
T
tema862016-10-15 15:59:47
Android
tema86, 2016-10-15 15:59:47

How to make smooth screen scrolling in an app?

Hello. There is a problem with scrolling text in the application.
I use for scrolling:
tv.setMovementMethod(new ScrollingMovementMethod());
Everything scrolls well, but not smoothly, that is,
the scrolling moves abruptly, there is no such thing that he waved his finger and everything shifted to the very bottom
(which is what you really need).
Please let me know what needs to be added or changed.
PS I don't use XML markup because I don't like it. Everything is in java, almost everything :)
Thank you.
Here is the code:

package somePackage;

import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.method.MovementMethod;
import android.text.method.ScrollingMovementMethod;
import android.view.MenuItem;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

public class prfd extends AppCompatActivity {

    TextView tv;
    String textout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        ActionBar actionBar = getSupportActionBar();
        actionBar.setDisplayHomeAsUpEnabled(true);
        super.onCreate(savedInstanceState);
        LinearLayout prl = new LinearLayout(this);
        prl.setOrientation(LinearLayout.VERTICAL);
        LinearLayout.LayoutParams prp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        setContentView(prl,prp);

        setTitle(R.string.sp);
        LinearLayout.LayoutParams trp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);

        tv = new TextView(this);
        tv.setId(R.id.tv);
        tv.setMovementMethod(new ScrollingMovementMethod());
        prl.addView(tv,trp);

        String[] prstr = getResources().getStringArray(R.array.stp);
        textout = "";

        for(int i=0; i<prstr.length; i++) {
            textout += prstr[i] + "\n";
        }

        tv.setText(textout);

    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                this.finish();
                return true;
        }
        return super.onOptionsItemSelected(item);
    }

    @Override
    public void onPause() {
        super.onPause();
        overridePendingTransition(0, 0);
    }
}

Answer the question

In order to leave comments, you need to log in

3 answer(s)
T
tema86, 2016-10-15
@tema86

Found the solution here:
stackoverflow.com/questions/11789777/dynamically-a...

F
FoxInSox, 2016-10-15
@FoxInSox

Please let me know what needs to be added or changed.

There is a bug somewhere in your code that needs to be fixed.

Y
Yuri, 2016-10-19
@YuryBorodkin

ScrollView. It's better, in my opinion, not to use the built-in scroll.
https://developer.android.com/reference/android/wi...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question