Answer the question
In order to leave comments, you need to log in
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
Found the solution here:
stackoverflow.com/questions/11789777/dynamically-a...
Please let me know what needs to be added or changed.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question