Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Android to imitate Wechat multi-person audio and video call interface

2025-01-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

Editor to share with you how to use Android imitation Wechat multi-person audio and video call interface, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

1. Use custom ViewGroup to implement

The following is the effect of three people talking on the phone. For others, please refer to the Wechat multi-person audio and video call interface.

Package com.dnaer.android.telephone.widgets;import android.content.Context;import android.os.Build;import android.support.annotation.RequiresApi;import android.util.AttributeSet;import android.util.DisplayMetrics;import android.view.View;import android.view.ViewGroup;import android.view.WindowManager;import com.anbetter.log.MLog;public class MultiVideoChatLayout extends ViewGroup implements CommLayoutAdapter.OnDataChangedListener {private CommLayoutAdapter mCommLayoutAdapter; private int mScreenWidth; / / the wide height private int mSizeModel1 in the state of 2pm, 3pm and 4. / / the wide height private int mSizeModel2; public MultiVideoChatLayout (Context context) {this (context, null);} public MultiVideoChatLayout (Context context, AttributeSet attrs) {this (context, attrs, 0);} public MultiVideoChatLayout (Context context, AttributeSet attrs, int defStyleAttr) {super (context, attrs, defStyleAttr); initialize (context) } @ RequiresApi (api = Build.VERSION_CODES.LOLLIPOP) public MultiVideoChatLayout (Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {super (context, attrs, defStyleAttr, defStyleRes); initialize (context);} private void initialize (Context context) {WindowManager wm = (WindowManager) context.getSystemService (Context.WINDOW_SERVICE); DisplayMetrics metrics = new DisplayMetrics (); wm.getDefaultDisplay (). GetMetrics (metrics); mScreenWidth = metrics.widthPixels; mSizeModel1 = mScreenWidth / 2; mSizeModel2 = mScreenWidth / 3 } @ Override protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec) {/ / defaults to the width of the screen, and the height directly takes the width to form a square final int width = MeasureSpec.makeMeasureSpec (mScreenWidth, MeasureSpec.EXACTLY); final int height = MeasureSpec.makeMeasureSpec (mScreenWidth, MeasureSpec.EXACTLY); setMeasuredDimension (width, height); MLog.d ("width:" + width + ", height:" + height); final int childWidth = MeasureSpec.makeMeasureSpec (mScreenWidth / 3, MeasureSpec.EXACTLY) Final int childHeight = MeasureSpec.makeMeasureSpec (mScreenWidth / 3, MeasureSpec.EXACTLY); final int childWidth3 = MeasureSpec.makeMeasureSpec (mScreenWidth / 2, MeasureSpec.EXACTLY); final int childHeight2 = MeasureSpec.makeMeasureSpec (mScreenWidth / 2, MeasureSpec.EXACTLY); if (getChildCount () > 4) {for (int I = 0; I)

< getChildCount(); i++) { View child = getChildAt(i); child.measure(childWidth, childHeight); } } else { for (int i = 0; i < getChildCount(); i++) { View child = getChildAt(i); child.measure(childWidth3, childHeight2); } } } @Override protected void onLayout(boolean changed, int l, int t, int r, int b) { if (getChildCount() 9) { throw IllegalArgumentException("${javaClass.simpleName}最多支持9个item布局, 请检查你的item个数是否正确") } mScreenWidth = Resources.getSystem().displayMetrics.widthPixels val itemSize = if (itemCount >

4) {mScreenWidth / 3} else {mScreenWidth / 2} if (itemCount layoutDecoratedWithMargins (view, 0,0, itemSize, itemSize) 1-> layoutDecoratedWithMargins (view, itemSize, 0, itemSize * 2, itemSize) else-> layoutDecoratedWithMargins (view, itemSize / 2, itemSize, itemSize + itemSize / 2) ItemSize * 2)} else {for (I in 0 until itemCount) {val view = recycler.getViewForPosition (I) addView (view) / / add measureChildWithMargins (view, 0,0) if (I% 2 = = 0) {layoutDecoratedWithMargins (view, 0, I / 2 * itemSize, itemSize, I / 2 * itemSize + itemSize)} else {layoutDecoratedWithMargins (view, itemSize, I / 2 * itemSize, 2 * itemSize) I / 2 * itemSize + itemSize)} else {var currentWidth = 0 for (I in 0 until itemCount) {val view = recycler.getViewForPosition (I) addView (view) / / add measureChildWithMargins (view, 0,0) if (I% 3 = = 0) {currentWidth = 0 layoutDecoratedWithMargins (view, 0, I / 3 * itemSize, itemSize, I / 3 * itemSize + itemSize)} else {layoutDecoratedWithMargins (view, currentWidth + itemSize) I / 3 * itemSize, currentWidth + 2 * itemSize, I / 3 * itemSize + itemSize) currentWidth + = itemSize}} / / because this layout does not require scrolling So directly cancel all the scrolling in both directions override fun canScrollHorizontally (): Boolean {return false} override fun canScrollVertically (): Boolean {return false}} above is all the content of the article "how to use Android to imitate Wechat multi-person audio and video call interface". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report