国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Android添加圖片到ListView或者RecyclerView顯示

2019-12-12 05:39:45
字體:
來源:轉載
供稿:網友

先上圖

 

點擊+號就去選擇圖片

實際上這個添加本身就是一個ListView或者 RecyclerView

只是布局有些特殊
item 

<?xml version="1.0" encoding="utf-8"?><liu.myrecyleviewchoosephoto.view.SquareRelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/rootView" android:layout_width="wrap_content" android:layout_height="wrap_content"> <RelativeLayout  android:layout_width="wrap_content"  android:layout_height="wrap_content"  android:layout_marginLeft="7dp"  android:layout_marginRight="7dp"  android:layout_marginTop="14dp"  android:background="@drawable/shape_white_bg_corner"  >  <ImageView   android:id="@+id/ivDisPlayItemPhoto"   android:layout_width="match_parent"   android:layout_height="match_parent"   android:contentDescription="@null"   android:scaleType="centerCrop"   android:layout_centerInParent="true"   android:layout_marginRight="8dp"   android:layout_marginLeft="8dp"   android:layout_marginTop="5dp"   android:layout_marginBottom="5dp"   />  <ImageView   android:id="@+id/ivAddPhoto"   android:layout_width="match_parent"   android:layout_height="match_parent"   android:layout_centerInParent="true"   android:background="@color/white"   android:scaleType="centerCrop"   android:src="@mipmap/add_photo_refund"   android:visibility="visible"/>  <ImageView   android:id="@+id/ivUploadingBg"   android:layout_width="match_parent"   android:layout_height="match_parent"   android:src="@drawable/shape_grey_bg_corner"   android:visibility="gone"/>  <ImageView   android:id="@+id/ivError"   android:layout_width="wrap_content"   android:layout_height="wrap_content"   android:layout_centerInParent="true"   android:src="@mipmap/icon_prompt"   android:visibility="gone"/>  <TextView   android:id="@+id/tvProgress"   android:layout_width="wrap_content"   android:layout_height="wrap_content"   android:layout_centerInParent="true"   android:text="0%"   android:textColor="@color/white"   android:textSize="16sp"   android:visibility="gone"/> </RelativeLayout> <ImageView  android:id="@+id/ivDelete"  android:layout_width="wrap_content"  android:layout_height="wrap_content"  android:layout_alignParentRight="true"  android:src="@mipmap/delete_photo"  android:visibility="gone"/></liu.myrecyleviewchoosephoto.view.SquareRelativeLayout> 

在Adpater中判斷一個數據是不是為0和是不是最后一個添加的圖片就可以了。

 @Override public int getItemCount() {  if (mDatas == null || mDatas.size() == 0) {   return 1;  } else if (mDatas.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

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 留坝县| 太原市| 蛟河市| 蛟河市| 塔城市| 营口市| 连城县| 项城市| 巫山县| 东山县| 通化县| 保定市| 达拉特旗| 新蔡县| 济阳县| 永修县| 平度市| 壶关县| 沙湾县| 京山县| 嘉善县| 玛多县| 合山市| 永康市| 梓潼县| 盐山县| 安陆市| 宣恩县| 银川市| 康保县| 环江| 呼图壁县| 靖安县| 徐汇区| 沧州市| 荃湾区| 福清市| 马尔康县| 平和县| 奉贤区| 威海市|