2
这是我现在纠缠一会儿,我使用HorizontalScrollView.fullScroll(HorizontalScrollView.FOCUS_RIGHT)
它滚动我的ScrollView的权利,但不是所有的方式,它需要滚动条99%右侧,我可以手动滚动其余的方式,但由于某种原因,它不会当我打电话给fullScroll()
API。Android - HorizontalScrollView不会一直滚动
下面是一个示例代码....如果您按下按钮几次,TextView将展开,您将看到问题。
活动: package com.example.test;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.HorizontalScrollView;
import android.widget.TextView;
public class MainActivity extends Activity {
TextView tv;
HorizontalScrollView hsv;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv = (TextView) findViewById(R.id.textView1);
hsv = (HorizontalScrollView)findViewById(R.id.horizontalScrollView1);
}
public void btnOnClick(View v) {
tv.append("a");
hsv.fullScroll(HorizontalScrollView.FOCUS_RIGHT);
}
}
布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<HorizontalScrollView
android:id="@+id/horizontalScrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="30sp"
android:text="push the button" />
</LinearLayout>
</HorizontalScrollView>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="btnOnClick"
android:text="Button" />
</LinearLayout>