Android customized listview realizes QQ space interface (including pictures, videos, likes, comments and forwarding functions)

The front-end time just needs to do a community sharing function similar to QQ space. The content includes text (topic, content), video, pictures, likes, comments, location information and other functions. Let's use listview to do one. Let's see the effect first. The GIF is too large and the CSDN can't be transmitted. Please move to gitee connection: gif effect

1. First analyze the controls contained in each item in the listview, as shown in the following figure

Sn 1: Avatar, ImageView, can be customized as a circle; Sn 2: user name, textview; Sn 3: release time, textview; No. 4: text part, textview; No. 5: talk about the video or picture part in the video view; No. 6: likes information, textview, dynamic addition; Serial number 7: location information, textview; Serial No. 8 / 9 / 10: like, comment and forward, all of which are ImageView; No. 11: comment area, textview, dynamic addition; No. 12: comment box, EditText. The picture on the right is set through drawableright. Event monitoring will be described in detail later;

One is missing in the above figure. There needs to be a play button in the center of the video, which is ImageView. You can switch between play and pause by switching the pictures in ImageView.

2. After determining which controls are available, we use XML to implement the layout, and the file is named video_ brower_ Item.xml, the code is as follows:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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">
 <LinearLayout
  android:id="@+id/mContainer"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="vertical"
  android:paddingLeft="10dp"
  android:paddingRight="10dp"
  android:paddingTop="10dp"
  android:background="@android:color/white">
  <LinearLayout
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:orientation="horizontal">
   <com.xiaok.winterolympic.custom.CircleImageView
    android:id="@+id/video_avatar"
    android:layout_width="45dp"
    android:layout_height="45dp"
    android:src="@drawable/head_picture" />
   <TextView
    android:id="@+id/video_username"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="xiaok"
    android:textColor="#000000"
    android:layout_marginStart="15dp"
    android:textSize="24sp"
    android:textStyle="bold" />
   <TextView
    android:id="@+id/video_date"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="20dp"
    android:textSize="14sp"
    android:text="刚刚"/>
  </LinearLayout>
  <TextView
   android:id="@+id/video_descripation"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:layout_marginTop="15dp"
   android:textSize="16sp"
   android:textColor="#000000"
   android:text="#共迎冬奥# 冬奥"/>
  <VideoView
   android:id="@+id/video_view"
   android:layout_width="match_parent"
   android:layout_height="230dp"
   android:layout_marginTop="15dp"/>
  <RelativeLayout
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:orientation="horizontal">
   <TextView
    android:id="@+id/video_position"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="北京市朝阳区"
    android:layout_marginTop="12dp"
    android:layout_alignParentStart="true"
    android:layout_marginBottom="10dp"/>
   <ImageView
    android:id="@+id/video_iv_good"
    style="@style/VideoShareImageView"
    android:src="@mipmap/video_share_good"
    android:layout_toStartOf="@+id/video_iv_comment"
    android:layout_marginEnd="20dp"/>
   <ImageView
    android:id="@+id/video_iv_comment"
    style="@style/VideoShareImageView"
    android:src="@mipmap/video_share_comment"
    android:layout_toStartOf="@+id/video_iv_share"
    android:layout_marginEnd="20dp"/>
   <ImageView
    android:id="@+id/video_iv_share"
    style="@style/VideoShareImageView"
    android:src="@mipmap/video_share_share"
    android:layout_alignParentEnd="true"
    android:layout_marginEnd="10dp"/>
  </RelativeLayout>
  <EditText
   android:id="@+id/video_et_comment"
   android:layout_width="match_parent"
   android:layout_height="40dp"
   android:hint="评论"
   android:textSize="14sp"
   android:layout_marginBottom="20dp"
   android:drawableRight="@drawable/video_send_picture"/>
 </LinearLayout>
 <ImageView
  android:id="@+id/video_play"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:src="@mipmap/ic_record_play"
  android:layout_gravity="center_horizontal"
  android:layout_marginTop="192dp"/>
</FrameLayout>

3. Define a class named videobrowser, which is used to encapsulate the data used by each entry in the listview:

package com.xiaok.winterolympic.model;
import java.io.Serializable;
public class VideoBrower implements Serializable {
  private static final long serialVersionUID = 1L;
  private int avatarId;
  private String username;
  private String date;
  private String videoDescripation;
  private String videoPath;
  private String position;
  public VideoBrower(int avatarId,String username,String date,String videoDescripation,String videoPath,String position) {
    this.avatarId = avatarId;
    this.username = username;
    this.date = date;
    this.videoDescripation = videoDescripation;
    this.videoPath = videoPath;
    this.position = position;
  }
  public int getAvatarId() {
    return avatarId;
  }
  public String getUsername() {
    return username;
  }
  public String getDate() {
    return date;
  }
  public String getVideoDescripation() {
    return videoDescripation;
  }
  public String getVideoPath() {
    return videoPath;
  }
  public String getPosition() {
    return position;
  }
  public void setAvatarId(int avatarId) {
    this.avatarId = avatarId;
  }
  public void setDate(String date) {
    this.date = date;
  }
  public void setUsername(String username) {
    this.username = username;
  }
  public void setVideoDescripation(String videoDescripation) {
    this.videoDescripation = videoDescripation;
  }
  public void setVideoPath(String videoPath) {
    this.videoPath = videoPath;
  }
  public void setPosition(String position) {
    this.position = position;
  }
}

As explained here, the avatar is implemented by encapsulating the corresponding resource ID in the R file, so the format is int, and others should not be explained.

summary

The above is the Android custom listview that Xiaobian introduced to you to realize the QQ space interface. I hope it will help you. If you have any questions, please leave me a message, and Xiaobian will reply to you in time. Thank you very much for your support to our website! If you think this article is helpful to you, welcome to reprint, please indicate the source, thank you!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>