zoukankan      html  css  js  c++  java
  • android gallery的使用

    1:

    xml 

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >


        <Gallery
            android:id="@+id/imagegallery"
            android:layout_width="fill_parent"
            android:layout_height="match_parent" />


    </LinearLayout>


    2:

    java文件

    package com.example.cloud.hdplayer2.faq;


    import android.app.Activity;
    import android.content.Context;
    import android.os.Bundle;
    import android.view.View;
    import android.view.ViewGroup;
    import android.view.ViewGroup.LayoutParams;
    import android.widget.BaseAdapter;
    import android.widget.Gallery;
    import android.widget.ImageView;


    public class ImageShowActivity extends Activity {
    private Gallery imagegallery;
    private ImageView image;
    private String pos;
    private ImageAdapter imageadapter;
    private int[] images = new int[] { R.drawable.m1, R.drawable.m2,
    R.drawable.m3, R.drawable.m1, R.drawable.m1, R.drawable.m1,
    R.drawable.m1 };


    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_imageshow);



    imagegallery = (Gallery) findViewById(R.id.imagegallery);
    imageadapter = new ImageAdapter(getApplicationContext());
    initview();
    }


    private void initview() {
    imagegallery.setAdapter(imageadapter);
    imagegallery.setSelection(0);

    }


    public class ImageAdapter extends BaseAdapter {
    private Context mContext;


    public ImageAdapter(Context context) {
    mContext = context;
    }


    public int getCount() {
    return images.length;
    }


    public Object getItem(int position) {
    return position;
    }


    public long getItemId(int position) {
    return position;
    }


    public View getView(int position, View convertView, ViewGroup parent) {
    ImageView image = new ImageView(mContext);
    image.setImageResource(images[position]);
    image.setAdjustViewBounds(true);
    image.setLayoutParams(new Gallery.LayoutParams(  
               LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    return image;
    }
    }


    }

  • 相关阅读:
    Qt QString转char[]数组
    Qt 如何使窗体初始最大化
    Qt 子窗口监听主窗口信号
    SQL SERVER 日志已满的处理方法 (转)
    C#中的sleep()和wait()
    C#中的sleep()和wait()
    C# 生成1100的随机数
    C# 生成1100的随机数
    gridcontrol 添加行号
    gridcontrol 添加行号
  • 原文地址:https://www.cnblogs.com/dyllove98/p/3215090.html
Copyright © 2011-2022 走看看