设为首页 加入收藏

TOP

Android添加图片到ListView或者 RecyclerView显示(二)
2017-10-13 10:35:59 】 浏览:2334
Tags:Android 添加 图片 ListView 或者 RecyclerView 显示
atas.size() < mMaxNum) { return mDatas.size() + 1; } else { return mDatas.size(); } }

 

这里用到了一个正方形的,容器

package liu.myrecyleviewchoosephoto.view;


import android.content.Context;
import android.util.AttributeSet;
import android.widget.RelativeLayout;

/**
 * 正方形的RelativeLayout
 * Created by 刘楠 on 2016/8/13 0013.16:07
 */
public class SquareRelativeLayout extends RelativeLayout {
    public SquareRelativeLayout(Context context) {
        super(context);
    }

    public SquareRelativeLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public SquareRelativeLayout(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {


        //设置自己测量结果
        setMeasuredDimension(getDefaultSize(0,widthMeasureSpec),getDefaultSize(0,heightMeasureSpec));


        /**
         * 测量子View的
         */
        int childWidthSize=getMeasuredWidth();
        //高度与宽度一样
        widthMeasureSpec =MeasureSpec.makeMeasureSpec(childWidthSize,MeasureSpec.EXACTLY);
        heightMeasureSpec =widthMeasureSpec;

        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }
}

 

这里没有写图片选择器
有兴趣可以看这里

 图片选择器:

https://github.com/ln0491/PhotoView

 

源码:

https://github.com/ln0491/MyRecyleViewChoosePhoto

 

首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Android打开相机和打开相册 下一篇Android开发实战(二十一):浅谈..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目