歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Android 圖片水平顯示 類Gallery效果

Android 圖片水平顯示 類Gallery效果

日期:2017/3/1 11:09:47   编辑:Linux編程
  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>
Copyright © Linux教程網 All Rights Reserved