<HorizontalScrollView android:id="@+id/horizontalScrollView1" android:layout_width="match_parent" android:layout_height="wrap_content" > </HorizontalScrollView>
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/scroller" android:layout_width="fill_parent" android:layout_height="fill_parent" android:fillViewport="true" > <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal"> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical"> <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Picture 1" /> <ImageView android:id="@+id/imageView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/pic_a" /> </LinearLayout> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical"> <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Picture 2" /> <ImageView android:id="@+id/imageView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/pic_b" /> </LinearLayout> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical"> <TextView android:id="@+id/textView3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Picture 3" /> <ImageView android:id="@+id/imageView3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/pic_c" /> </LinearLayout> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical"> <TextView android:id="@+id/textView4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Picture 3" /> <ImageView android:id="@+id/imageView4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/pic_d" /> </LinearLayout> </LinearLayout> </HorizontalScrollView>
package com.myapp; import android.os.Bundle; import android.app.Activity; import android.view.Menu; public class MainActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_main, menu); return true; } }
package com.myapp; import android.os.Bundle; import android.app.Activity; import android.view.Gravity; import android.view.Menu; import android.widget.HorizontalScrollView; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; public class MainActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //setContentView(R.layout.activity_main); HorizontalScrollView hsv = new HorizontalScrollView(this); LinearLayout ll = new LinearLayout(this); ll.setOrientation(LinearLayout.HORIZONTAL); hsv.addView(ll); // Column 1 LinearLayout ll1 = new LinearLayout(this); ll1.setOrientation(LinearLayout.VERTICAL); ll.addView(ll1); // Picture 1 & pic_a TextView tv1 = new TextView(this); tv1.setText("Picture 1"); tv1.setGravity(Gravity.CENTER_VERTICAL); ll1.addView(tv1); ImageView iv1 = new ImageView(this); iv1.setImageResource(R.drawable.pic_a); ll1.addView(iv1); // Column 2 LinearLayout ll2 = new LinearLayout(this); ll2.setOrientation(LinearLayout.VERTICAL); ll.addView(ll2); // Picture 2 & pic_b TextView tv2 = new TextView(this); tv2.setText("Picture 2"); tv2.setGravity(Gravity.CENTER_VERTICAL); ll2.addView(tv2); ImageView iv2 = new ImageView(this); iv2.setImageResource(R.drawable.pic_b); ll2.addView(iv2); // Column 3 LinearLayout ll3 = new LinearLayout(this); ll3.setOrientation(LinearLayout.VERTICAL); ll.addView(ll3); // Picture 3 & pic_c TextView tv3 = new TextView(this); tv3.setText("Picture 3"); tv3.setGravity(Gravity.CENTER_VERTICAL); ll3.addView(tv3); ImageView iv3 = new ImageView(this); iv3.setImageResource(R.drawable.pic_c); ll3.addView(iv3); // Column 4 LinearLayout ll4 = new LinearLayout(this); ll4.setOrientation(LinearLayout.VERTICAL); ll.addView(ll4); // Picture 4 & pic_d TextView tv4 = new TextView(this); tv4.setText("Picture 4"); tv4.setGravity(Gravity.CENTER_VERTICAL); ll4.addView(tv4); ImageView iv4 = new ImageView(this); iv4.setImageResource(R.drawable.pic_d); ll4.addView(iv4); this.setContentView(hsv); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_main, menu); return true; } }
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Test ScrollView and HorizontalScrollView "/> <HorizontalScrollView android:layout_width="wrap_content" android:layout_height="wrap_content"> <LinearLayout android:orientation="horizontal" android:layout_width="wrap_content" android:layout_height="wrap_content"> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button 1" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button 2" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button 3" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button 4" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button 5" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button 6" /> </LinearLayout> </HorizontalScrollView> <ScrollView android:layout_height="fill_parent" android:layout_width="fill_parent"> <LinearLayout android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="wrap_content" > <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button 1" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button 2" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button 3" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button 4" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button 5" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button 6" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button 7" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button 8" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button 9" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button 10" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button 11" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button 12" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button 13" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button 14" /> </LinearLayout> </ScrollView> </LinearLayout>
ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท