仿微信朋友圈

布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:fresco="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/kuang_8dp_touying"
        android:padding="@dimen/dp_10"
        android:layout_marginBottom="@dimen/dp_20"
        android:orientation="vertical">
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <com.facebook.drawee.view.SimpleDraweeView
                android:id="@+id/fragment_circle_sdv_image"
                android:layout_width="50dp"
                android:layout_height="50dp"
                android:layout_alignParentLeft="true"
                fresco:roundWithOverlayColor="@android:color/white"
                fresco:roundedCornerRadius="8dp" />
            <TextView
                android:id="@+id/fragment_circle_txt_name"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textSize="14sp"
                android:layout_centerVertical="true"
                android:layout_toRightOf="@+id/fragment_circle_sdv_image"
                android:layout_marginLeft="15dp" />
            <TextView
                android:id="@+id/fragment_circle_txt_date"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textSize="10sp"
                android:layout_centerVertical="true"
                android:layout_alignParentRight="true"
                android:layout_marginRight="10dp"/>
        </RelativeLayout>

        <TextView
            android:id="@+id/fragment_circle_txt_content"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:layout_marginBottom="10dp"
            android:ellipsize="end"
            android:gravity="center"
            android:maxLines="1"
            android:textSize="12sp" />

        <xhw.bwie.com.bwshop.utils.RecyclerGridView
            android:id="@+id/grid_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
        </xhw.bwie.com.bwshop.utils.RecyclerGridView>
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="@dimen/dp_30"
            android:gravity="right"
            android:layout_marginTop="@dimen/dp_20"
            android:orientation="horizontal">
            <TextView
                android:id="@+id/fragment_circle_txt_zan"
                android:layout_width="@dimen/dp_20"
                android:layout_height="@dimen/dp_20"
                />
            <TextView
                android:id="@+id/fragment_circle_txt_zannum"
                android:layout_width="@dimen/dp_30"
                android:layout_height="match_parent"
                android:gravity="center"
                android:textSize="12sp"
                android:layout_marginLeft="@dimen/dp_10"/>
        </LinearLayout>
    </LinearLayout>



</LinearLayout>

里面的图片布局就一张图片

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <com.facebook.drawee.view.SimpleDraweeView
        android:layout_width="match_parent"
        android:id="@+id/iv"

        app:roundTopLeft="true"

        app:roundTopRight="true"

        app:roundBottomLeft="true"
        app:roundedCornerRadius="20dp"
        app:roundBottomRight="true"
       app:placeholderImage="@mipmap/commom_tab_btn_shoppingcart"
        android:layout_height="@dimen/dp_90"
        android:layout_marginLeft="@dimen/dp_2"
        android:layout_marginRight="@dimen/dp_2"
        />

</android.support.constraint.ConstraintLayout>

一个xrecycler的适配器

public class Circle_Adapter extends XRecyclerView.Adapter<Circle_Adapter.ViewHolder> {
    private final FragmentActivity context;
    private List<Circle_Resule_Bean> list;

    public Circle_Adapter(FragmentActivity activity) {
        this.context=activity;
        this.list=new ArrayList<>();
    }
    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = View.inflate(context, R.layout.new_circle, null);
        ViewHolder viewHolder = new ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        Uri uri = Uri.parse(list.get(position).getHeadPic());
        holder.fragmentCircleSdvImage.setImageURI(uri);
        holder.fragmentCircleTxtName.setText(list.get(position).getNickName());
        //转换成日期格式
        SimpleDateFormat dateFormat = new SimpleDateFormat(Urls.DATA,Locale.getDefault());
        holder.fragmentCircleTxtDate.setText(dateFormat.format(list.get(position).getCreateTime()));
        holder.fragmentCircleTxtContent.setText(list.get(position).getContent());
        holder.fragmentCircleTxtZanNum.setText(""+list.get(position).getGreatNum());
        /*holder.fragmentCircleTxtZan.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Animation animation = AnimationUtils.loadAnimation(context, R.anim.add_score_anim);
                holder.fragmentCircleTxtZanNum.setVisibility(View.VISIBLE);
                holder.fragmentCircleTxtZanNum.startAnimation(animation);
                holder.fragmentCircleTxtZan.setBackgroundResource(R.drawable.zans);
                new Handler().postDelayed(new Runnable() {
                    public void run() {
                        holder.fragmentCircleTxtZanNum.setVisibility(View.GONE);
                    }
                }, 1000);
            }
        });*/
      //最关键的代码
        if (StringUtils.isEmpty(list.get(position).getImage())){
            holder.gridView.setVisibility(View.GONE);
        }else{
            holder.gridView.setVisibility(View.VISIBLE);
            String[] images = list.get(position).getImage().split(",");
            int imageCount = (int) ((Math.random() * 9) + 1);
            int colNum;//列数
            if (imageCount == 1){
                colNum = 1;
            }else if (imageCount == 2||imageCount == 4){
                colNum = 2;
            }else {
                colNum = 3;
            }
            holder.imageAdapter.clear();
            for (int i = 0; i < imageCount; i++) {
                holder.imageAdapter.addAll(Arrays.asList(images));

            }
            holder.gridView.setNumColumns(colNum);
            holder.imageAdapter.notifyDataSetChanged();
        }
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public void setData(List<Circle_Resule_Bean> result) {
        if (list!=null){
            this.list.clear();
            this.list=result;
            notifyDataSetChanged();
        }

    }
    public class ViewHolder extends RecyclerView.ViewHolder {
        private final SimpleDraweeView fragmentCircleSdvImage;
        private final TextView fragmentCircleTxtName;
        private final TextView fragmentCircleTxtDate;
        private final TextView fragmentCircleTxtContent;
        private final ImageAdapter imageAdapter;
        private final RecyclerGridView gridView;
        private final TextView fragmentCircleTxtZan;
        private final TextView fragmentCircleTxtZanNum;

        public ViewHolder(View itemView) {
            super(itemView);
            fragmentCircleSdvImage = itemView.findViewById(R.id.fragment_circle_sdv_image);
            fragmentCircleTxtName = itemView.findViewById(R.id.fragment_circle_txt_name);
            fragmentCircleTxtDate = itemView.findViewById(R.id.fragment_circle_txt_date);
            fragmentCircleTxtContent = itemView.findViewById(R.id.fragment_circle_txt_content);
            fragmentCircleTxtZan = itemView.findViewById(R.id.fragment_circle_txt_zan);
            fragmentCircleTxtZanNum = itemView.findViewById(R.id.fragment_circle_txt_zannum);
            gridView = itemView.findViewById(R.id.grid_view);
            imageAdapter = new ImageAdapter();
            int space = context.getResources().getDimensionPixelSize(R.dimen.dp_10);;//图片间距
            gridView.setHorizontalSpacing(space);
            gridView.setVerticalSpacing(space);
            gridView.setAdapter(imageAdapter);
        }
    }
}

判断图片多少的工具类

public class StringUtils {
    public final static String UTF_8 = "UTF-8";

    /**
     * 判断字符串是否有值,如果为null或者是空字符串或者只有空格或者为"null"字符串,则返回true,否则则返回false
     */
    public static boolean isEmpty(String value) {
        if (value != null && !"".equalsIgnoreCase(value.trim())
                && !"null".equalsIgnoreCase(value.trim())) {
            return false;
        } else {
            return true;
        }
    }
    Pattern p = Pattern
            .compile("^((13[0-9])|(15[^4,\\D])|(18[0-9]))\\d{8}$");
    /**
     * 验证手机号码
     *
     * @param mobiles
     * @return [0-9]{5,9}
     */
    public boolean isMobileNO(String mobiles) {
        try {

            Matcher m = p.matcher(mobiles);
            return m.matches();
        } catch (Exception e) {
        }
        return false;
    }
}
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值