Android 自定義ListView實(shí)現(xiàn)QQ空間界面(說說內(nèi)包含圖片、視頻、點(diǎn)贊、評(píng)論、轉(zhuǎn)發(fā)功能)
前端時(shí)間剛好需要做一個(gè)類似于QQ空間的社區(qū)分享功能,說說內(nèi)容包含文字(話題、內(nèi)容)、視頻、圖片,還需包含點(diǎn)贊,評(píng)論,位置信息等功能。 就采用LIstview做了一個(gè),先來看下效果,GIF太大,CSDN傳不了,請(qǐng)移步Gitee連接:GIF效果
1. 先來分析一下ListView中每一個(gè)條目包含的控件,請(qǐng)看下圖
序號(hào)1:頭像,ImageView,自定義為圓形即可;
序號(hào)2:用戶名,TextView;
序號(hào)3:發(fā)布時(shí)間,TextView;
序號(hào)4:說說文字部分,TextView;
序號(hào)5:說說中視頻或圖片部分,Videoview;
序號(hào)6:點(diǎn)贊信息,TextView,動(dòng)態(tài)添加;
序號(hào)7:位置信息,TextView;
序號(hào)8/9/10:點(diǎn)贊、評(píng)論、轉(zhuǎn)發(fā),均為ImageView;
序號(hào)11:評(píng)論區(qū),TextView,動(dòng)態(tài)添加;
序號(hào)12:評(píng)論框,EditText,其右側(cè)圖片是通過drawableRight設(shè)置的,事件監(jiān)聽會(huì)在后面詳細(xì)說;
上面圖中漏了一個(gè),在視頻正中央還需要有一個(gè)播放按鈕,為ImageView,通過切換ImageView中圖片實(shí)現(xiàn)播放與暫停切換。
2. 確定好有哪些控件后,我們用xml實(shí)現(xiàn)布局,文件命名為video_brower_item.xml,代碼如下:
<?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="北京市朝陽區(qū)" 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="評(píng)論" 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. 定義一個(gè)類,這里命名為VideoBrower,用于封裝ListView中每個(gè)條目所用到的數(shù)據(jù):
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; } }
這里解釋下,頭像我是通過封裝R文件中對(duì)應(yīng)的資源ID實(shí)現(xiàn)的,所以格式為int,其他應(yīng)該不用解釋。
總結(jié)
以上所述是小編給大家介紹的Android 自定義ListView實(shí)現(xiàn)QQ空間界面,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)我們網(wǎng)站的支持!
如果你覺得本文對(duì)你有幫助,歡迎轉(zhuǎn)載,煩請(qǐng)注明出處,謝謝!
上一篇:android實(shí)現(xiàn)簡(jiǎn)單音樂播放器
欄 目:Android
下一篇:Android項(xiàng)目遷移到AndroidX的方法步驟
本文標(biāo)題:Android 自定義ListView實(shí)現(xiàn)QQ空間界面(說說內(nèi)包含圖片、視頻、點(diǎn)贊、評(píng)論、轉(zhuǎn)發(fā)功能)
本文地址:http://mengdiqiu.com.cn/a1/Android/8976.html
您可能感興趣的文章
- 01-10Android自定義View之繪制圓形頭像功能
- 01-10Android實(shí)現(xiàn)雙擊返回鍵退出應(yīng)用實(shí)現(xiàn)方法詳解
- 01-10android實(shí)現(xiàn)記住用戶名和密碼以及自動(dòng)登錄
- 01-10android實(shí)現(xiàn)簡(jiǎn)單計(jì)算器功能
- 01-10Android 友盟第三方登錄與分享的實(shí)現(xiàn)代碼
- 01-10C++自定義API函數(shù)實(shí)現(xiàn)大數(shù)相乘算法
- 01-10android實(shí)現(xiàn)指紋識(shí)別功能
- 01-10Emoji表情在Android JNI中的兼容性問題詳解
- 01-10Android實(shí)現(xiàn)圓形漸變加載進(jìn)度條
- 01-10android開發(fā)環(huán)境中SDK文件夾下的所需內(nèi)容詳解


閱讀排行
- 1C語言 while語句的用法詳解
- 2java 實(shí)現(xiàn)簡(jiǎn)單圣誕樹的示例代碼(圣誕
- 3利用C語言實(shí)現(xiàn)“百馬百擔(dān)”問題方法
- 4C語言中計(jì)算正弦的相關(guān)函數(shù)總結(jié)
- 5c語言計(jì)算三角形面積代碼
- 6什么是 WSH(腳本宿主)的詳細(xì)解釋
- 7C++ 中隨機(jī)函數(shù)random函數(shù)的使用方法
- 8正則表達(dá)式匹配各種特殊字符
- 9C語言十進(jìn)制轉(zhuǎn)二進(jìn)制代碼實(shí)例
- 10C語言查找數(shù)組里數(shù)字重復(fù)次數(shù)的方法
本欄相關(guān)
- 01-10Android自定義View之繪制圓形頭像功能
- 01-10Android實(shí)現(xiàn)雙擊返回鍵退出應(yīng)用實(shí)現(xiàn)方
- 01-10android實(shí)現(xiàn)簡(jiǎn)單計(jì)算器功能
- 01-10android實(shí)現(xiàn)記住用戶名和密碼以及自動(dòng)
- 01-10C++自定義API函數(shù)實(shí)現(xiàn)大數(shù)相乘算法
- 01-10Android 友盟第三方登錄與分享的實(shí)現(xiàn)代
- 01-10android實(shí)現(xiàn)指紋識(shí)別功能
- 01-10如何給Flutter界面切換實(shí)現(xiàn)點(diǎn)特效
- 01-10Android實(shí)現(xiàn)圓形漸變加載進(jìn)度條
- 01-10Emoji表情在Android JNI中的兼容性問題詳
隨機(jī)閱讀
- 01-11ajax實(shí)現(xiàn)頁面的局部加載
- 01-10使用C語言求解撲克牌的順子及n個(gè)骰子
- 01-10delphi制作wav文件的方法
- 01-10SublimeText編譯C開發(fā)環(huán)境設(shè)置
- 08-05織夢(mèng)dedecms什么時(shí)候用欄目交叉功能?
- 04-02jquery與jsp,用jquery
- 08-05dedecms(織夢(mèng))副欄目數(shù)量限制代碼修改
- 01-10C#中split用法實(shí)例總結(jié)
- 08-05DEDE織夢(mèng)data目錄下的sessions文件夾有什
- 01-11Mac OSX 打開原生自帶讀寫NTFS功能(圖文