Android 图片水平显示 类Gallery效果


  1. HorizontalScrollView scrollView = (HorizontalScrollView) this.findViewById(R.id.scrollView);  
  2.         TableRow row = (TableRow) scrollView.findViewById(R.id.row);  
  3.         for (int i = 0; i < 5; i++) {  
  4.             ImageView imageView = new ImageView(this);  
  5.             imageView.setImageResource(R.drawable.k);  
  6.             row.addView(imageView);  
  7.         }  
  8.         this.setContentView(scrollView);  

布局文件

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <HorizontalScrollView  
  3.     Android:id="@+id/scrollView"  
  4.     xmlns:android="http://schemas.android.com/apk/res/android"  
  5.     android:layout_width="fill_parent" android:layout_height="fill_parent">  
  6.     <TableLayout android:layout_width="fill_parent"  
  7.         android:layout_height="fill_parent">  
  8.         <TableRow android:id="@+id/row" android:layout_width="fill_parent"  
  9.             android:layout_height="fill_parent" />  
  10.     </TableLayout>  
  11. </HorizontalScrollView>  

相关内容