Android ScrollView布局
解决UI过多,屏幕显示不下的问题!
主程序:
package com.example.androidviewscrolltest; import android.os.Bundle; import android.app.Activity; import android.view.Menu; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } }
布局文件xml如下:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" > <RelativeLayout android:id="@+id/myScrollView" android:layout_width="match_parent" android:layout_height="404dp" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/tv1" android:text="@string/hello_world1" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/tv1" android:id="@+id/tv2" android:text="@string/hello_world2" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/tv2" android:id="@+id/tv3" android:text="@string/hello_world3" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/tv3" android:id="@+id/tv4" android:text="@string/hello_world4" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/tv4" android:id="@+id/tv5" android:text="@string/hello_world5" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/tv5" android:id="@+id/tv6" android:text="@string/hello_world6" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/tv6" android:id="@+id/tv7" android:text="@string/hello_world7" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/tv7" android:id="@+id/tv8" android:text="@string/hello_world8" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/tv8" android:id="@+id/tv9" android:text="@string/hello_world9" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/tv9" android:id="@+id/tv10" android:text="@string/hello_world10" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/tv10" android:id="@+id/tv11" android:text="@string/hello_world11" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/tv11" android:id="@+id/tv12" android:text="@string/hello_world12" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/tv12" android:id="@+id/tv13" android:text="@string/hello_world13" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/tv13" android:id="@+id/tv14" android:text="@string/hello_world14" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/tv14" android:id="@+id/tv15" android:text="@string/hello_world15" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world12" /> </RelativeLayout> </ScrollView>
显示效果:
这个是解决UI过多的情况.
有些像阅读器,文本显示不下的情况,是如下解决方式:
<?xmlversion="1.0"encoding="utf-8"?> <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <ScrollView android:id="@+id/myScrollView" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" android:id="@+id/myTextView" /> </ScrollView> </LinearLayout>
主程序代码和上面一样,注意ScrollView的位置.

浙公网安备 33010602011771号