• 王立平--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>






  • 相关阅读:
    app被Rejected 的各种原因翻译
    UIView Border color
    Centos7下安装docker
    利用Yum彻底移除docker
    Docker删除全部镜像和容器
    【转】哈哈笑一笑
    【转】KAFKA分布式消息系统
    java读取properties文件
    java反序列化php序列化的对象
    Java 1.7.0_06中String类内部实现的一些变化【转】
  • 原文地址:https://www.cnblogs.com/cynchanpin/p/7214309.html
Copyright © 2020-2023  润新知