当您TextView中的字数太多,不足以在屏幕上完整显示时,如何使一个TextView用ScrollView滚动显示呢? 下面我举一个简单的例子: 代码: import java.io.File; import java.io.FileInputStream; import java.io.IOException; import org.apache.http.util.EncodingUtils; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.ScrollView; import android.widget.TextView; import android.widget.Toast; public class pass extends Activity { /** Called when the activity is first created. */ final String TEXT_ENCODING = "UTF-8"; ScrollView sv; TextView tv; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.passdialog); sv=(ScrollView)findViewById(R.id.sv); tv=(TextView)findViewById(R.id.txtView); tv.setText("mmmmmmmmmmmmmmmmmmmmm" + "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" + "llllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll"+ "gggggggggggggggggggggggggggggggggggggggggggggggggg" + "vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv," + "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq" + "hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh"); } } passdialog.xml: <?xml version="1.0" encoding="utf-8"?> <AbsoluteLayout android:id="@+id/widget38" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android" > <LinearLayout android:id="@+id/widget32" android:layout_width="wrap_content" android:layout_height="wrap_content" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_x="0px" android:layout_y="0px" > </LinearLayout> <ScrollView android:id="@+id/sv" android:layout_width="wrap_content" android:layout_height="wrap_content" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_x="0px" android:layout_y="20px" > <TextView android:id="@+id/txtView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="22sp" android:gravity="center_vertical" > </TextView> </ScrollView> </AbsoluteLayout>