<ScrollView android:id="@+id/scrollView1" android:layout_width="match_parent" android:layout_height="wrap_content" > </ScrollView>
<ScrollView 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="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" /> <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" /> <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" /> <TextView android:id="@+id/textView4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Picture 4" /> <ImageView android:id="@+id/imageView4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/pic_d" /> </LinearLayout> </ScrollView>
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.ImageView; import android.widget.LinearLayout; import android.widget.ScrollView; import android.widget.TextView; public class MainActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //setContentView(R.layout.activity_main); ScrollView sv = new ScrollView(this); LinearLayout ll = new LinearLayout(this); ll.setOrientation(LinearLayout.VERTICAL); sv.addView(ll); // Picture 1 & pic_a TextView tv1 = new TextView(this); tv1.setText("Picture 1"); tv1.setGravity(Gravity.CENTER_VERTICAL); ll.addView(tv1); ImageView iv1 = new ImageView(this); iv1.setImageResource(R.drawable.pic_a); ll.addView(iv1); // Picture 2 & pic_b TextView tv2 = new TextView(this); tv2.setText("Picture 2"); tv2.setGravity(Gravity.CENTER_VERTICAL); ll.addView(tv2); ImageView iv2 = new ImageView(this); iv2.setImageResource(R.drawable.pic_b); ll.addView(iv2); // Picture 3 & pic_c TextView tv3 = new TextView(this); tv3.setText("Picture 3"); tv3.setGravity(Gravity.CENTER_VERTICAL); ll.addView(tv3); ImageView iv3 = new ImageView(this); iv3.setImageResource(R.drawable.pic_c); ll.addView(iv3); // Picture 4 & pic_d TextView tv4 = new TextView(this); tv4.setText("Picture 4"); tv4.setGravity(Gravity.CENTER_VERTICAL); ll.addView(tv4); ImageView iv4 = new ImageView(this); iv4.setImageResource(R.drawable.pic_d); ll.addView(iv4); this.setContentView(sv); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_main, menu); return true; } }
ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท