Android 앱에서 자동 스크롤을 시도하고 있습니다.
다음과 같은 xml 코드가 있다고 가정합니다.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="show me the texts"
android:id="@+id/button"/>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/text"
android:id="@+id/textView1"/>
</ScrollView>
</LinearLayout>
이 XML 코드에는 화면 상단에 Button이 있고 ScrollView로 래핑 된 TextView가 있습니다. 그것은 내 TextView가 지금 스크롤 가능하다는 것을 의미합니다.
사용자가 화면을 터치하고 아래로 또는 위로 바꿀 때 TextView를 위아래로 스크롤 할 수 있기 때문에 올바르게 작동합니다.
그러나...
자동 스크롤 가능한 TextView를 가질 계획이며 자동으로 10 초 후에 약 10dp 아래로 스크롤되는 스크롤 가능한 TextView가 필요합니다.
시간을 계산하기 위해 내 응용 프로그램에서 일부 스레드를 사용해야한다는 것을 알고 있지만 예를 들어 10 초 후에 TextView 스크롤을 내리는 방법을 모르겠습니다.
어떤 제안? 모든 힌트를 주시면 감사하겠습니다. 감사
다음과 같은 것을 사용할 수 있습니다.
mScrollView.post(new Runnable() {
public void run() {
mScrollView.smoothScrollBy(10, 10);
}
});
smoothScrollBy에 대한 문서 : http://developer.android.com/reference/android/widget/ScrollView.html#smoothScrollBy(int,int)
이 작업을 10 초마다 실행하려면 :
TimerTask fileProcessTask = new TimerTask(){
@Override
public void run() {
//Scrolling here
}
};
Timer tm = new Timer();
tm.schedule(fileProcessTask, 10000L);
또한이 SO Post를 살펴보십시오 : https://stackoverflow.com/a/14685729/3326331 , 나는 시도하지 않았지만 시도해 볼 수 있습니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다