Code Monkey home page Code Monkey logo

multiview's Introduction

#MultiView --- Android显示多图或item的View

gradle依赖

    compile 'cn.lemon:multiview:0.1.8'

###MultiView基本使用:

由于依赖了RestHttp,所以初始化:

  RestHttp.initialize(this);
  if(BuildConfig.DEBUG){
       RestHttp.setDebug(true,"network");
  }

xml布局文件

    <cn.lemon.multi.MultiView
        android:id="@+id/multi_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:background="#f1506d"
        app:divideSpace="8dp"
        app:placeholder="@drawable/holder"/>
  • 设置item之间的间隔app:divideSpace="8dp"
  • 设置占位图app:placeholder="@drawable/holder"

java代码:

 multiView = (multiView) findViewById(R.id.cell_view);
 multiView.setLayoutParams(new LinearLayout.LayoutParams(900, ViewGroup.LayoutParams.WRAP_CONTENT));

 data.add("http://i02.pictn.sogoucdn.com/73a90748d5e19769");
 data.add("http://i01.pictn.sogoucdn.com/e19188bbc3966d6f");
 data.add("http://i02.pictn.sogoucdn.com/85db79c962886004");
 data.add("http://i01.pictn.sogoucdn.com/f44c1591194be8b9");

 multiView.setImages(data);   设置图片资源

如果你不只是显示图片,需要自定义item的情况,这个时候就需要添加一个自定义Adapter继承Adapter:

    class MyAdapter extends Adapter<String> {

        private TextView textView;
        public MyAdapter(Context context) {
            super(context);
        }

        @Override
        public View getView(ViewGroup parent, int position) {
            View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item,parent,false);
            textView = (TextView) view.findViewById(R.id.text);
            return view;
        }

        @Override
        public void setData(String object) {
            super.setData(object);
            //view绑定数据
            textView.setText(object);
        }

        @Override
        public void setOnItemClick() {
            super.setOnItemClick();
            //item点击事件
        }
    }

设置Adapter,添加数据就好了

   adapter = new MyAdapter(this);
   multiView.setAdapter(adapter);
   adapter.addAll(data);

###ViewImageActivity 基本使用:

在manifests文件中添加

   <activity android:name="cn.lemon.multi.ui.ViewImageActivity"/>

不管是否使用MultiView,其实都可以使用ViewImageActivity,只需要在跳转Activity的时候绑定好数据,如:

   intent.putExtra(LookImageActivity.IMAGES_DATA_LIST, (Serializable) picUrlData);   //这里的数据集合必须是List<Stirng>
   intent.putExtra(LookImageActivity.IMAGE_NUM, data.indexOf(object));

主要还是使用在加载多张图片的时候和MultiView联合使用。

####注意事项

依赖的其他库

   compile 'com.android.support:appcompat-v7:23.1.1'
   compile 'com.android.support:support-v4:23.1.1'
   compile 'cn.alien95:resthttp:1.0.5'

###详细用法请看Demo

####显示图片

####自定义item

multiview's People

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.