最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時間:2016年08月15日 17:09:57   作者:森林森  
這篇文章主要介紹了Android添加圖片到ListView或者RecyclerView顯示的相關(guān)資料,需要的朋友可以參考下

先上圖

 

點擊+號就去選擇圖片

實際上這個添加本身就是一個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中判斷一個數(shù)據(jù)是不是為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) {


  //設(shè)置自己測量結(jié)果
  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

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • flutter  TextField換行自適應(yīng)的實現(xiàn)

    flutter TextField換行自適應(yīng)的實現(xiàn)

    這篇文章主要介紹了flutter TextField換行自適應(yīng)的實現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-02-02
  • Android判斷Activity是否在最上層的方法

    Android判斷Activity是否在最上層的方法

    這篇文章主要介紹了Android判斷Activity是否在最上層的方法,涉及Android針對Activity屬性判斷與操作相關(guān)技巧,代碼非常簡單易懂,需要的朋友可以參考下
    2016-01-01
  • Android最簡單的狀態(tài)切換布局實現(xiàn)教程

    Android最簡單的狀態(tài)切換布局實現(xiàn)教程

    這篇文章主要給大家介紹了關(guān)于Android中最簡單的狀態(tài)切換布局的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2018-10-10
  • Android開發(fā)實戰(zhàn)之漂亮的ViewPager引導(dǎo)頁

    Android開發(fā)實戰(zhàn)之漂亮的ViewPager引導(dǎo)頁

    這篇文章主要介紹了Android開發(fā)實戰(zhàn)中漂亮ViewPager引導(dǎo)頁的制作過程,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-08-08
  • Android中Fragment相互切換間不被回收的實現(xiàn)方法

    Android中Fragment相互切換間不被回收的實現(xiàn)方法

    這篇文章主要給大家介紹了關(guān)于Android中Fragment相互切換間不被回收的實現(xiàn)方法,文中給出了詳細(xì)的示例代碼和注釋供大家參考學(xué)習(xí),對大家具有一定的參考學(xué)習(xí)價值,需要的朋友們下面來一起看看吧。
    2017-08-08
  • Android仿微信聯(lián)系人字母排序效果

    Android仿微信聯(lián)系人字母排序效果

    大家使用到的聯(lián)系人界面,幾乎都是按照字母排序,如何實現(xiàn)聯(lián)系人按字母排序?下面就為大家詳解介紹了Android仿微信聯(lián)系人按字母排序的實現(xiàn)方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-11-11
  • Android編程實現(xiàn)獲取多媒體庫視頻、音頻、圖片的方法

    Android編程實現(xiàn)獲取多媒體庫視頻、音頻、圖片的方法

    這篇文章主要介紹了Android編程實現(xiàn)獲取多媒體庫視頻、音頻、圖片的方法,涉及Android針對多媒體視頻、音頻及相關(guān)專輯圖片、縮略圖等獲取操作實現(xiàn)技巧,需要的朋友可以參考下
    2018-01-01
  • Android開發(fā)之微信底部菜單欄實現(xiàn)的幾種方法匯總

    Android開發(fā)之微信底部菜單欄實現(xiàn)的幾種方法匯總

    這篇文章主要介紹了Android開發(fā)之微信底部菜單欄實現(xiàn)的幾種方法,下面小編把每種方法通過實例逐一給大家介紹,需要的朋友可以參考下
    2016-09-09
  • Android11繞過反射限制的方法

    Android11繞過反射限制的方法

    這篇文章主要介紹了Android11繞過反射限制的方法,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-09-09
  • RxJava取消訂閱的各種方式的實現(xiàn)

    RxJava取消訂閱的各種方式的實現(xiàn)

    這篇文章主要介紹了RxJava取消訂閱的各種方式的實現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-09-09

最新評論

江北区| 河北区| 客服| 高陵县| 汨罗市| 连州市| 晋江市| 固原市| 土默特左旗| 江山市| 洛扎县| 稷山县| 清河县| 丰台区| 屏东县| 龙海市| 克山县| 岳阳市| 商城县| 新化县| 平南县| 桃园市| 额济纳旗| 上饶市| 确山县| 固镇县| 辛集市| 行唐县| 尼玛县| 沧州市| 吉木乃县| 中宁县| 濉溪县| 马龙县| 大新县| 罗江县| 延安市| 丽江市| 甘洛县| 安义县| 江阴市|