【android基础】之关于重复类型事件的处理方法

1、

 

 

看下具体的实现:

1.main.xml文件

 

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/bg"
    android:scrollbars="vertical" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >

        <!-- 横排开始 -->
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="horizontal" >

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="5dp"
                android:layout_marginTop="15dp"
                android:background="@drawable/circle_corner1"
                android:orientation="vertical" >

                <ImageView
                    android:id="@+id/mg1"
                    android:onClick="myClick"
                    android:layout_width="100dp"
                    android:layout_height="100dp"
                    android:layout_gravity="left"
                    android:padding="10dp"
                    android:scaleType="fitXY"
                    android:src="@drawable/img01" />

             
            </LinearLayout>

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="5dp"
                android:layout_marginTop="15dp"
                android:background="@drawable/circle_corner1"
                android:orientation="vertical" >

                <ImageView
                     android:onClick="myClick"
                    android:layout_width="100dp"
                    android:layout_height="100dp"
                    android:layout_gravity="left"
                    android:padding="10dp"
                    android:scaleType="fitXY"
                    android:src="@drawable/img01" />

             
            </LinearLayout>

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="5dp"
                android:layout_marginTop="15dp"
                android:background="@drawable/circle_corner1"
                android:orientation="vertical" >

                <ImageView
                     android:onClick="myClick"
                    android:layout_width="100dp"
                    android:layout_height="100dp"
                    android:layout_gravity="left"
                    android:padding="10dp"
                    android:scaleType="fitXY"
                    android:src="@drawable/img01" />

            </LinearLayout>
        </LinearLayout>
  <!-- 横排结束 -->
               <!-- 横排开始 -->
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="horizontal" >

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="5dp"
                android:layout_marginTop="15dp"
                android:background="@drawable/circle_corner1"
                android:orientation="vertical" >

                <ImageView
                     android:onClick="myClick"
                    android:layout_width="100dp"
                    android:layout_height="100dp"
                    android:layout_gravity="left"
                    android:padding="10dp"
                    android:scaleType="fitXY"
                    android:src="@drawable/img01" />

             
            </LinearLayout>

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="5dp"
                android:layout_marginTop="15dp"
                android:background="@drawable/circle_corner1"
                android:orientation="vertical" >

                <ImageView
                     android:onClick="myClick"
                    android:layout_width="100dp"
                    android:layout_height="100dp"
                    android:layout_gravity="left"
                    android:padding="10dp"
                    android:scaleType="fitXY"
                    android:src="@drawable/img01" />

           
            </LinearLayout>

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="5dp"
                android:layout_marginTop="15dp"
                android:background="@drawable/circle_corner1"
                android:orientation="vertical" >

                <ImageView
                     android:onClick="myClick"
                    android:layout_width="100dp"
                    android:layout_height="100dp"
                    android:layout_gravity="left"
                    android:padding="10dp"
                    android:scaleType="fitXY"
                    android:src="@drawable/img01" />

              
            </LinearLayout>
        </LinearLayout>
  <!-- 横排结束 -->
  
          <!-- 横排开始 -->
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="horizontal" >

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="5dp"
                android:layout_marginTop="15dp"
                android:background="@drawable/circle_corner1"
                android:orientation="vertical" >

                <ImageView
                     android:onClick="myClick"
                    android:layout_width="100dp"
                    android:layout_height="100dp"
                    android:layout_gravity="left"
                    android:padding="10dp"
                    android:scaleType="fitXY"
                    android:src="@drawable/img01" />

             
            </LinearLayout>

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="5dp"
                android:layout_marginTop="15dp"
                android:background="@drawable/circle_corner1"
                android:orientation="vertical" >

                <ImageView
                     android:onClick="myClick"
                    android:layout_width="100dp"
                    android:layout_height="100dp"
                    android:layout_gravity="left"
                    android:padding="10dp"
                    android:scaleType="fitXY"
                    android:src="@drawable/img01" />

              
            </LinearLayout>

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="5dp"
                android:layout_marginTop="15dp"
                android:background="@drawable/circle_corner1"
                android:orientation="vertical" >

                <ImageView
                     android:onClick="myClick"
                    android:layout_width="100dp"
                    android:layout_height="100dp"
                    android:layout_gravity="left"
                    android:padding="10dp"
                    android:scaleType="fitXY"
                    android:src="@drawable/img01" />

             
            </LinearLayout>
        </LinearLayout>
  <!-- 横排结束 -->
  
          <!-- 横排开始 -->
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="horizontal" >

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="5dp"
                android:layout_marginTop="15dp"
                android:background="@drawable/circle_corner1"
                android:orientation="vertical" >

                <ImageView
                     android:onClick="myClick"
                    android:layout_width="100dp"
                    android:layout_height="100dp"
                    android:layout_gravity="left"
                    android:padding="10dp"
                    android:scaleType="fitXY"
                    android:src="@drawable/img01" />

             
            </LinearLayout>

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="5dp"
                android:layout_marginTop="15dp"
                android:background="@drawable/circle_corner1"
                android:orientation="vertical" >

                <ImageView
                     android:onClick="myClick"
                    android:layout_width="100dp"
                    android:layout_height="100dp"
                    android:layout_gravity="left"
                    android:padding="10dp"
                    android:scaleType="fitXY"
                    android:src="@drawable/img01" />

              
            </LinearLayout>

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="5dp"
                android:layout_marginTop="15dp"
                android:background="@drawable/circle_corner1"
                android:orientation="vertical" >

                <ImageView
                     android:onClick="myClick"
                    android:layout_width="100dp"
                    android:layout_height="100dp"
                    android:layout_gravity="left"
                    android:padding="10dp"
                    android:scaleType="fitXY"
                    android:src="@drawable/img01" />

             
            </LinearLayout>
        </LinearLayout>
  <!-- 横排结束 -->
  
          <!-- 横排开始 -->
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="horizontal" >

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="5dp"
                android:layout_marginTop="15dp"
                android:background="@drawable/circle_corner1"
                android:orientation="vertical" >

                <ImageView
                     android:onClick="myClick"
                    android:layout_width="100dp"
                    android:layout_height="100dp"
                    android:layout_gravity="left"
                    android:padding="10dp"
                    android:scaleType="fitXY"
                    android:src="@drawable/img01" />

             
            </LinearLayout>

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="5dp"
                android:layout_marginTop="15dp"
                android:background="@drawable/circle_corner1"
                android:orientation="vertical" >

                <ImageView
                     android:onClick="myClick"
                    android:layout_width="100dp"
                    android:layout_height="100dp"
                    android:layout_gravity="left"
                    android:padding="10dp"
                    android:scaleType="fitXY"
                    android:src="@drawable/img01" />

               
            </LinearLayout>

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="5dp"
                android:layout_marginTop="15dp"
                android:background="@drawable/circle_corner1"
                android:orientation="vertical" >

                <ImageView
                     android:onClick="myClick"
                    android:layout_width="100dp"
                    android:layout_height="100dp"
                    android:layout_gravity="left"
                    android:padding="10dp"
                    android:scaleType="fitXY"
                    android:src="@drawable/img01" />

             
            </LinearLayout>
        </LinearLayout>
  <!-- 横排结束 -->
          <!-- 横排开始 -->
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="horizontal" >

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="5dp"
                android:layout_marginTop="15dp"
                android:background="@drawable/circle_corner1"
                android:orientation="vertical" >

                <ImageView
                     android:onClick="myClick"
                    android:layout_width="100dp"
                    android:layout_height="100dp"
                    android:layout_gravity="left"
                    android:padding="10dp"
                    android:scaleType="fitXY"
                    android:src="@drawable/img01" />

            </LinearLayout>

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="5dp"
                android:layout_marginTop="15dp"
                android:background="@drawable/circle_corner1"
                android:orientation="vertical" >

                <ImageView
                     android:onClick="myClick"
                    android:layout_width="100dp"
                    android:layout_height="100dp"
                    android:layout_gravity="left"
                    android:padding="10dp"
                    android:scaleType="fitXY"
                    android:src="@drawable/img01" />

             
            </LinearLayout>

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="5dp"
                android:layout_marginTop="15dp"
                android:background="@drawable/circle_corner1"
                android:orientation="vertical" >

                <ImageView
                     android:onClick="myClick"
                    android:layout_width="100dp"
                    android:layout_height="100dp"
                    android:layout_gravity="left"
                    android:padding="10dp"
                    android:scaleType="fitXY"
                    android:src="@drawable/img01" />

               
            </LinearLayout>
        </LinearLayout>
  <!-- 横排结束 -->
  
    </LinearLayout>

</ScrollView>

 

 

2. MyOnClickListener.java文件

public void myClick(View target) {
  Intent intent;
  switch (target.getId()) {
  case R.id.mg1:
   intent  = new Intent(ImageListActivity.this, ImageSwitcher.class);
   startActivity(intent);
   break;
  case R.id.mg2:
    intent  = new Intent(ImageListActivity.this, ImageSwitcher.class);
   startActivity(intent);
   break;
  case R.id.mg3:
   intent  = new Intent(ImageListActivity.this, ImageSwitcher.class);
   startActivity(intent);
   break;
  case R.id.mg4:
   intent  = new Intent(ImageListActivity.this, ImageSwitcher.class);
   startActivity(intent);
   break;

.......
  default:
   break;
  }
  
 }

 

 

上一篇:近乎快速上手:如此强大的软件仅需10步即可学会


下一篇:Android开发:由模块化到组件化(一)