Я боролся с этим больше недели и наконец понял, как заставить это работать!
Моя проблема заключалась в том, что все будет прокручиваться как «блок». Сам текст прокручивался, но скорее как кусок, чем строка за строкой. Это, очевидно, не работает для меня, потому что это будет отрезать линии внизу. Все предыдущие решения не помогли мне, поэтому я разработал собственное.
Вот самое простое решение на сегодняшний день:
Создайте файл класса с именем: 'PerfectScrollableTextView' внутри пакета, затем скопируйте и вставьте этот код в:
import android.content.Context;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.widget.TextView;
public class PerfectScrollableTextView extends TextView {
public PerfectScrollableTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
setVerticalScrollBarEnabled(true);
setHorizontallyScrolling(false);
}
public PerfectScrollableTextView(Context context, AttributeSet attrs) {
super(context, attrs);
setVerticalScrollBarEnabled(true);
setHorizontallyScrolling(false);
}
public PerfectScrollableTextView(Context context) {
super(context);
setVerticalScrollBarEnabled(true);
setHorizontallyScrolling(false);
}
@Override
protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
if(focused)
super.onFocusChanged(focused, direction, previouslyFocusedRect);
}
@Override
public void onWindowFocusChanged(boolean focused) {
if(focused)
super.onWindowFocusChanged(focused);
}
@Override
public boolean isFocused() {
return true;
}
}
Наконец, измените ваш TextView в XML:
От: <TextView
Кому: <com.your_app_goes_here.PerfectScrollableTextView