15. ListView Item settings

        Of course, I want the ListView to display a custom layout, display text and pictures, as follows:

The layout is not difficult, just try more. In fact, I don't want to say much about the layout. Modify item_list.xml as follows:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 	xmlns:android="http://schemas.android.com/apk/res/android"
    	android:layout_width="match_parent"
    	android:layout_height="wrap_content"
   	android:paddingLeft="@dimen/padding_s"
    	android:paddingRight="@dimen/padding_s"
    	android:paddingTop="0dp"
    	android:paddingBottom="@dimen/padding_s"
    	android:orientation="vertical" >
    	<RelativeLayout
	    	android:layout_width="match_parent"
	    	android:layout_height="wrap_content"
	    	android:paddingLeft="@dimen/padding_n"
	    	android:paddingRight="@dimen/padding_n"
	    	android:paddingTop="@dimen/padding_ll"
	    	android:paddingBottom="@dimen/padding_s"
	    	android:background="@color/white_dark" >
        	<ImageView
            	android:id="@+id/iv_icon"
            	android:layout_width="@dimen/header_h_2"
	    		android:layout_height="@dimen/header_h_2"
	    		android:layout_alignParentLeft="true"
	    		android:layout_alignParentTop="true"
	    		android:src="@drawable/ic_launcher" />
        	<TextView
            	android:id="@+id/tv_name"
            	android:layout_width="wrap_content"
	    		android:layout_height="@dimen/header_h_2"
	    		android:layout_alignParentTop="true"
	    		android:layout_toRightOf="@+id/iv_icon"
	    		android:layout_marginLeft="@dimen/margin_ss"
	    		android:gravity="center_vertical"
	    		android:textSize="@dimen/text_level2"
	    		android:textColor="@color/text_level2"
	    		android:text="Username example"
	    		android:singleLine="true"/>
        	<TextView
            	android:id="@+id/tv_time"
            	android:layout_width="wrap_content"
	    		android:layout_height="@dimen/header_h_2"
	    		android:layout_alignParentTop="true"
	    		android:layout_alignParentRight="true"
	    		android:gravity="center_vertical"
	    		android:textSize="@dimen/text_level3"
	    		android:textColor="@color/text_level3"
	    		android:text="2016-11-12"
	    		android:singleLine="true" />
        	<ImageView
            	android:id="@+id/iv_time"
            	android:layout_width="@dimen/header_h_2"
	    		android:layout_height="@dimen/header_h_2"
	    		android:paddingLeft="@dimen/padding_ss"
	    		android:paddingRight="@dimen/padding_ss"
	    		android:layout_marginRight="0dp"
	    		android:layout_toLeftOf="@+id/tv_time"
	    		android:layout_alignParentTop="true"
	    		android:src="@drawable/time"
	    		android:tint="@color/text_level3" />
        	<TextView
            	android:id="@+id/tv_title"
            	android:layout_width="match_parent"
	    		android:layout_height="wrap_content"
	    		android:layout_below="@+id/iv_icon"
	    		android:layout_marginTop="@dimen/margin_ll"
	    		android:layout_marginBottom="@dimen/margin_n"
	    		android:textSize="@dimen/text_level1"
	    		android:textColor="@color/text_level1"
	    		android:text="Title example, what is the size" />
        	<TextView
            	android:id="@+id/tv_data"
            	android:layout_width="match_parent"
	    		android:layout_height="wrap_content"
	    		android:layout_below="@+id/tv_title"
	    		android:layout_marginBottom="@dimen/margin_s"
	    		android:lineSpacingMultiplier="1.14"
	    		android:textSize="@dimen/text_level2"
	    		android:textColor="@color/text_level2"
	    		android:text="Content example, how is the size. Content example, how is the size. Content example, how is the size. Content example, how is the size. Content example, how is the size. Content example, how is the size"
	    		android:visibility="visible" />
	</RelativeLayout>
	<RelativeLayout
        	android:id="@+id/rl_data"
        	android:layout_width="match_parent"
        	android:layout_height="100dp"
        	android:visibility="visible"
        	android:background="@color/white_dark">
    	</RelativeLayout>
	<LinearLayout
        	android:layout_width="match_parent"
        	android:layout_height="wrap_content"
        	android:padding="@dimen/padding_n"
        	android:background="@color/white_dark">
		<View
	        	android:layout_width="match_parent"
	        	android:layout_height="1dp"
	        	android:background="@color/gray_light"/>
    	</LinearLayout>
    	<TextView
        	android:id="@+id/tv_read"
        	android:layout_width="match_parent"
    		android:layout_height="wrap_content"
    		android:paddingTop="@dimen/padding_s"
    		android:paddingLeft="@dimen/padding_n"
    		android:paddingRight="@dimen/padding_n"
    		android:paddingBottom="@dimen/padding_ll"
    		android:textSize="@dimen/text_level2"
    		android:textColor="@color/text_level3"
    		android:text="2K read • 54 replies • original"
    		android:singleLine="true"
    		android:background="@color/white_dark" />
</LinearLayout>

        On the top left is the user avatar, username, title below, text content below, and a layout below for adding some pictures dynamically in code, and below is a browsing statistics.
        Modify ListAdapter

@Override
public View getView(final int position, View convertView, ViewGroup parent) {
	// TODO Auto-generated method stub
	final Holder holder;
	
	if(convertView==null){
		convertView=activity.getLayoutInflater().inflate(
R.layout.item_list, parent, false);
	
		holder=new Holder();
		convertView.setTag (holder);
	}
	else{
		holder=(Holder)convertView.getTag();
	}
	holder.iv_icon=(ImageView)convertView.findViewById(R.id.iv_icon);
	holder.tv_name=(TextView)convertView.findViewById(R.id.tv_name);
			holder.tv_time=(TextView)convertView.findViewById(R.id.tv_time);
	holder.tv_title=(TextView)convertView.findViewById(R.id.tv_title);
	holder.tv_data=(TextView)convertView.findViewById(R.id.tv_data);
	holder.rl_data=(RelativeLayout)convertView.findViewById(R.id.rl_data);
	holder.tv_read=(TextView)convertView.findViewById(R.id.tv_read);
	
	return convertView;
}

private class Holder{
		
	ImageView iv_icon;
	TextView tv_name;
	TextView tv_time;
	TextView tv_title;
	TextView tv_data;
		
	RelativeLayout rl_data;
	TextView tv_lmgctrl;//Leave him alone
	TextView tv_gifctrl;//with her
	GifImageView giv_data;//and him
	ProgressBar pb_load;//And it
		
	TextView tv_read;
}

        The running effect will not be posted. Similar to the picture above, the picture is dynamically added by the code, and I will talk about it later.

Forging ahead——2017/05/19


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326285620&siteId=291194637