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;
    }
    }


    }

  • 相关阅读:
    fiddler 抓包工具(新猿旺学习总结)
    Monkey之常用ADB命令(新猿旺学习总结)
    APP压力测试 monkey(新猿旺学习总结)
    linux 系统shell运行程序不退出
    c++字节对齐编译器指令#pragma
    vmware 14 新安装centos7 没法联网
    windows dll的def文件
    c编译器字节对齐指令
    centos 7 进入图形界面
    cent os 7 与cent os 6区别
  • 原文地址:https://www.cnblogs.com/dyllove98/p/3215090.html
Copyright © 2011-2022 走看看