需求:视频通话界面,两个surfaceView一个显示本端的视图,另一个显示对端的视图,由于显示比例的问题总会存在一个覆盖另一个的问题,为保证用户体验,规定小的覆盖大的视图上面,且点击小的视图可切花为大图视图居中,达到两个视图切花的功能。简单写一个demo完成功能的测试需求,为了较少文章的篇幅,视图的内容用回执矩形代替(实际开发中显示的是本地照相采集的数据和对端经过opgl处理的数据)
简单的布局
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
android:id="@+id/remote_rl"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
android:id="@+id/remote_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center" />android:id="@+id/local_rl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
android:id="@+id/local_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
具体的demo实现
public class MainActivity extends Activity implements View.OnClickListener {
public static final String TAG = "sssss";
//远端的视图
private SurfaceView remote_sv;
// 本地的视图
private SurfaceView local_sv;
private SurfaceHolder remote_holder;
private SurfaceHolder local_holder;
private RelativeLayout remote_rl;
private RelativeLayout local_rl;
private int screenWidth;
private int screenHeight;
private int beforRemoteweith;
private int beforLocalweith;
private int beforRemoteheigth;
private int beforLocalheigth;
private int StateAB = 0;
private int StateBA = 1;
private int mSate;
private int defaultLocalHeight=200;
private int defaultLocalwidth=400;