检查此链接http://android.okhelp.cz/horizontalscrollview-scrollview-horizontal-vertical-android-xml-example/
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageButton;
public class HorizontalscroolActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ImageButton btn11 = (ImageButton) findViewById(R.id.imageButton1);
ImageButton btn2 = (ImageButton) findViewById(R.id.imageButton2);
ImageButton btn3 = (ImageButton) findViewById(R.id.imageButton3);
ImageButton btn4 = (ImageButton) findViewById(R.id.imageButton4);
}
}
在 XML 文件中
<?xml version="1.0" encoding="utf-8"?>
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:src="@drawable/pic7"
android:text="image1" />
<TextView
android:id="@+id/text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Textview1" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:orientation="vertical"
android:layout_height="fill_parent">
<ImageButton
android:text="image2"
android:id="@+id/imageButton2"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:src="@drawable/pic2" />
<TextView
android:id="@+id/text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Textview2" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:orientation="vertical"
android:layout_height="fill_parent">
<ImageButton
android:text="image3"
android:id="@+id/imageButton3"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:src="@drawable/pic7" />
<TextView
android:id="@+id/text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Textview3" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:orientation="vertical"
android:layout_height="fill_parent">
<ImageButton
android:text="image4"
android:id="@+id/imageButton4"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:src="@drawable/pic5" />
<TextView
android:id="@+id/text4"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Textview4" />
</LinearLayout>
</LinearLayout>
</HorizontalScrollView>