У меня есть это представление для отображения видео
<FrameLayout
android:id="@+id/remoteViewLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="@+id/remote_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<RelativeLayout
android:id="@+id/local_view"
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_gravity="bottom|right" />
</FrameLayout>
После нажатия на local_view
мне нужно удалить виды из обоих RelativeLayout
и снова добавить их в другое положение.Я использую флаг, чтобы узнать текущие загруженные представления.
private String loadedView = "1";
binding.contentSinchIncomingCall.localView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (videoController == null) {
videoController = mSinchServiceInterface.getVideoController();
}
if (loadedView.equals("1")) {
loadedView = "2";
((ViewGroup) videoController.getLocalView().getParent()).removeView(videoController.getLocalView());
((ViewGroup) videoController.getRemoteView().getParent()).removeView(videoController.getRemoteView());
binding.contentSinchIncomingCall.remoteView.addView(videoController.getLocalView());
binding.contentSinchIncomingCall.localView.addView(videoController.getRemoteView());
binding.contentSinchIncomingCall.localView.requestLayout();
binding.contentSinchIncomingCall.localView.invalidate();
binding.contentSinchIncomingCall.remoteViewLayout.bringChildToFront(binding.contentSinchIncomingCall.localView);
} else {
loadedView = "1";
((ViewGroup) videoController.getLocalView().getParent()).removeView(videoController.getLocalView());
((ViewGroup) videoController.getRemoteView().getParent()).removeView(videoController.getRemoteView());
binding.contentSinchIncomingCall.remoteView.addView(videoController.getRemoteView());
binding.contentSinchIncomingCall.localView.addView(videoController.getLocalView());
binding.contentSinchIncomingCall.localView.requestLayout();
binding.contentSinchIncomingCall.localView.invalidate();
binding.contentSinchIncomingCall.remoteViewLayout.bringChildToFront(binding.contentSinchIncomingCall.localView);
}
}
});
Но после изменения позиций, remote_view
перекрывается local_view
.Я использую метод takeChildToFront для вывода local_view
на передний план, но все еще не работает.Пожалуйста, помогите мне решить эту проблему.
Скриншоты: - ![First loaded views](https://i.stack.imgur.com/cqsoc.png)
![After click](https://i.stack.imgur.com/oIJub.png)