Android add image to ListView or Recyclerview display

Source: Internet
Author: User

First

Click on the + sign to select a picture

In fact, this addition itself is a ListView or Recyclerview

It's just some special layout.

Item

<?XML version= "1.0" encoding= "Utf-8"?><Liu.myrecyleviewchoosephoto.view.SquareRelativeLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Android:id= "@+id/rootview"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content">    <RelativelayoutAndroid: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"        >        <ImageViewAndroid: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"            />        <ImageViewAndroid: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"/>        <ImageViewAndroid:id= "@+id/ivuploadingbg"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"android:src= "@drawable/shape_grey_bg_corner"android:visibility= "Gone"/>        <ImageViewAndroid: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"/>        <TextViewAndroid: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>    <ImageViewAndroid: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>

In adpater to determine whether a data is 0 and is not the last one to add the picture on it.

@Override      Public int GetItemCount () {        ifnull | | mdatas.size () = = 0)            {return 1  ;         Else if (Mdatas.size () < mmaxnum) {            return mdatas.size () + 1;         Else {            return  mdatas.size ();        }    }

Here's a square, a container.

 PackageLiu.myrecyleviewchoosephoto.view;ImportAndroid.content.Context;ImportAndroid.util.AttributeSet;Importandroid.widget.RelativeLayout;/*** Square relativelayout * Created by Liu Nan on 2016/8/13 0013.16:07*/ Public classSquarerelativelayoutextendsRelativelayout { PublicSquarerelativelayout (Context context) {Super(context); }     PublicSquarerelativelayout (Context context, AttributeSet attrs) {Super(context, attrs); }     PublicSquarerelativelayout (context context, AttributeSet attrs,intdefstyleattr) {        Super(context, attrs, defstyleattr); } @Overrideprotected voidOnmeasure (intWidthmeasurespec,intHeightmeasurespec) {        //set your own measurement resultsSetmeasureddimension (Getdefaultsize (0,widthmeasurespec), getdefaultsize (0, Heightmeasurespec)); /*** Measure sub-view*/        intChildwidthsize=getmeasuredwidth (); //the height is the same as the widthWidthmeasurespec =Measurespec.makemeasurespec (childwidthsize,measurespec.exactly); Heightmeasurespec=Widthmeasurespec; Super. Onmeasure (Widthmeasurespec, Heightmeasurespec); }}

No picture selector is written here.
Interested to see here

Picture selector:

Https://github.com/ln0491/PhotoView

Source:

Https://github.com/ln0491/MyRecyleViewChoosePhoto

Android Add picture to ListView or Recyclerview display

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.