【原创,转载注明出处】如何使用ScrollView实现Layout滚动

实现ScrollView跟LinearLayout,TableLayout的结合..

不废话,上代码。

XML文件:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical" >

<HorizontalScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content" >

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<TableLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<TextView
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:maxLines="10"
android:scrollbars="vertical"
android:singleLine="false"
android:text="TextView"
android:textSize="12dp" />

<CheckBox
android:id="@+id/mCB1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/mCB1"
android:textSize="10dp" />

<CheckBox
android:id="@+id/mCB2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/mCB2"
android:textSize="10dp" />

<CheckBox
android:id="@+id/mCB3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/mCB3"
android:textSize="10dp" />

<CheckBox
android:id="@+id/mCB4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/mCB4"
android:textSize="10dp" />

<CheckBox
android:id="@+id/mCB5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/mCB5"
android:textSize="10dp" />

<CheckBox
android:id="@+id/mCB6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/mCB6"
android:textSize="10dp" />

<CheckBox
android:id="@+id/mCB7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/mCB7"
android:textSize="10dp" />

<TableRow >

<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_column="0"
android:text="上一题"
android:textSize="10dp" />

<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_column="1"
android:text="查看答案"
android:textSize="10dp" />

<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_column="2"
android:text="TextView"
android:textSize="10dp" />

<Button
android:id="@+id/button3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_column="3"
android:text="偶是未知"
android:textSize="10dp" />

<Button
android:id="@+id/button4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_column="4"
android:text="下一题"
android:textSize="10dp" />
</TableRow>
<TextView
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:maxLines="10"
android:scrollbars="vertical"
android:singleLine="false"
android:text="TextView"
android:textSize="12dp" />

<CheckBox
android:id="@+id/mCB1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/mCB1"
android:textSize="10dp" />

<CheckBox
android:id="@+id/mCB2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/mCB2"
android:textSize="10dp" />

<CheckBox
android:id="@+id/mCB3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/mCB3"
android:textSize="10dp" />

<CheckBox
android:id="@+id/mCB4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/mCB4"
android:textSize="10dp" />

<CheckBox
android:id="@+id/mCB5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/mCB5"
android:textSize="10dp" />

<CheckBox
android:id="@+id/mCB6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/mCB6"
android:textSize="10dp" />

<CheckBox
android:id="@+id/mCB7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/mCB7"
android:textSize="10dp" />

<TableRow >

<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_column="0"
android:text="上一题"
android:textSize="10dp" />

<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_column="1"
android:text="查看答案"
android:textSize="10dp" />

<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_column="2"
android:text="TextView"
android:textSize="10dp" />

<Button
android:id="@+id/button3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_column="3"
android:text="偶是未知"
android:textSize="10dp" />

<Button
android:id="@+id/button4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_column="4"
android:text="下一题"
android:textSize="10dp" />
</TableRow>
</TableLayout>
</LinearLayout>
</HorizontalScrollView>

</ScrollView>

代码文件:

package hi.zcping.scrollview;

import android.app.Activity;
import android.os.Bundle;

public class ScrollViewActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}

Strings.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>

<string name="hello">Hello World, HiBabyDragonActivity!</string>
<string name="app_name">test</string>
<string name="str_1">Hi! BabyDragon.</string>
<string name="str_about_us">爸爸妈妈祝宝宝健健康康,快快乐乐。。</string>
<string name="str_about_us_dad"> zcping</string>
<string name="str_about_us_mam"> syan</string>
<string name="str_about_us_date"> 2012-02-28</string>
<string name="mCB1">mCB1</string>
<string name="mCB2">mCB2</string>
<string name="mCB3">mCB3</string>
<string name="mCB4">mCB4</string>
<string name="mCB5">mCB5</string>
<string name="mCB6">mCB6</string>
<string name="mCB7">mCB7</string>
</resources>

【原创,转载注明出处】如何使用ScrollView实现Layout滚动

【原创,转载注明出处】如何使用ScrollView实现Layout滚动