zoukankan      html  css  js  c++  java
  • 王立平--Gallery:实现图片的左右滑动


    <span style="font-size:18px;color:#330033;">package com.main;
    
    import android.app.Activity;
    import android.content.Context;
    import android.os.Bundle;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.BaseAdapter;
    import android.widget.Gallery;
    import android.widget.ImageView;
    
    @SuppressWarnings("deprecation")
    public class MainActivity extends Activity {
         Gallery gallery;
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            gallery = (Gallery)findViewById(R.id.gallery);
            gallery.setAdapter(new ImageAdapter(this));
            gallery.pointToPosition(0, 0);
       
        }
    
        
        class ImageAdapter extends BaseAdapter{
    
              private Context context;
              //图片源数组
              private Integer[] imageInteger={
    
                     R.drawable.ic_launcher,
                     R.drawable.bg3,
                     R.drawable.ic_launcher,
                     R.drawable.bg3,
                     R.drawable.ic_launcher,
                     R.drawable.bg3,
                     R.drawable.ic_launcher,
                     R.drawable.bg3
              };
    
              public ImageAdapter(Context c){
    
                 context = c;
    
              }
    
              @Override
    
              public int getCount() {
    
                 return imageInteger.length;
    
              }
    
              @Override
    
              public Object getItem(int position) {
    
                 return position;
    
              }
    
              @Override
    
              public long getItemId(int position) {
    
                 // TODO Auto-generated method stub
    
                 return position;
    
              }
    
              @Override
    
              public View getView(int position, View convertView, ViewGroup parent) {
    
                 ImageView imageView = new ImageView(context);
    
                 imageView.setImageResource(imageInteger[position]);
    
                 imageView.setScaleType(ImageView.ScaleType.FIT_XY);
    
                  return imageView;
    
              }}
    
    
    }</span>
    -----------------------------------------------------------------------------------------
    <span style="font-size:18px;color:#330033;"><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    
        xmlns:tools="http://schemas.android.com/tools" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" > 
        
       <Gallery 
           android:id="@+id/gallery" 
           android:layout_width="fill_parent" 
           android:layout_height="fill_parent" 
           android:layout_alignParentTop="true" 
           android:gravity="fill_vertical" 
           android:spacing="10dp" 
           android:background="#0000FF" 
           android:padding="0dp" 
           /> 
       
    </RelativeLayout>
    
     </span>






  • 相关阅读:
    awk中执行Linux命令的两种方式
    Hibernate-validator校验含javax.validation.constraints注解的对象其首次校验长耗时问题
    Linux系统查看端口常用命令
    简要记录搭建Nexus私服过程(发布和使用)
    简要记录搭建Nexus私服过程(配置)
    简要记录搭建Nexus私服过程(安装)
    [转载] jar包和war包的介绍和区别
    linux-exec
    linux-vim格式设置
    linux-array
  • 原文地址:https://www.cnblogs.com/cynchanpin/p/7214309.html
Copyright © 2011-2022 走看看