Overlaying youtube Api Videos in View Pager - android

My multiple youtube videos in viewPager overlaying itself and youtubePlayer stops after one second recording. My first video works fine, but whenever I slide to another or back to previous one and try to record it I give an overlaying error. I try to set the videoContainer to gone, release the youtube player, bringToFront() current videoContainer, hide/show detach/attach videoFragment and the problem still remains.The detach/attach fragment solution works but not every time.
My warn message: YouTube video playback stopped due to unauthorized overlay on top of player. The YouTubePlayerView is obscured by android.widget.LinearLayout{54f27e3 V.E...... ........ 0,0-1080,1584 #7f1000ec app:id/globalViewLinearLayout}. Right edge 50 px right of YouTubePlayerView's left edge.
My FragmentViewPagerItemXML:
<LinearLayout 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"
android:orientation="vertical"
android:id="#+id/globalViewLinearLayout">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/backgroundContent">
<com.app.CustomScrollView
android:id="#+id/customScrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/scrollViewLinearLayout">
<FrameLayout
android:id="#+id/mediaContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="220dp"
android:layout_marginBottom="80dp"
android:visibility="gone"
android:id="#+id/videoContainerLayout">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="200dp"
android:id="#+id/videoContainer"
android:orientation="vertical" />
</LinearLayout>
<RelativeLayout
android:layout_marginTop="5dp"
android:layout_width="match_parent"
android:layout_height="#dimen/imageHeight"
android:id="#+id/galleryContainer"
android:layout_marginBottom="55dp">
<ProgressBar
android:id="#+id/progress"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_centerInParent="true" />
<RelativeLayout
android:id="#+id/photoWithButtonsContainer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="#color/black">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/themePhoto"
android:clickable="true"
android:adjustViewBounds="true"
android:padding="10dp"
android:background="#android:color/white"
android:layout_centerInParent="true"
android:visibility="gone" />
<ImageButton
android:layout_alignRight="#+id/themePhoto"
android:layout_alignTop="#+id/themePhoto"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
android:layout_margin="8dp"
android:layout_width="35dp"
android:layout_height="35dp"
android:background="#drawable/expand"
android:id="#+id/zoomMe"
android:visibility="gone" />
</RelativeLayout>
</RelativeLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="25dp"
android:layout_gravity="bottom|right"
android:id="#+id/buttonLinearLayout">
<android.support.design.widget.FloatingActionButton
android:layout_width="50dp"
android:layout_height="50dp"
android:id="#+id/playButton"
android:src="#drawable/ic_play_arrow_black_48dp"
app:backgroundTint="#color/white"
android:layout_marginRight="15dp"
android:layout_marginEnd="15dp"
android:visibility="gone" />
<android.support.design.widget.FloatingActionButton
app:backgroundTint="#color/white"
android:layout_width="50dp"
android:layout_height="50dp"
android:id="#+id/videoButton"
android:layout_marginRight="15dp"
android:layout_marginEnd="15dp"
android:src="#drawable/ic_ondemand_video_black_48dp"
android:visibility="gone" />
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_gravity="bottom|left"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:layout_height="85dp"
android:background="#drawable/ribbon"
android:id="#+id/artWorkCounter"
android:textColor="#color/white"
android:textSize="12sp"
android:textStyle="bold"
android:gravity="center"
android:paddingLeft="2dp"
android:paddingRight="2dp" />
</FrameLayout>
Code:
public View onCreateView(LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) {
videoContainer = (LinearLayout) view.findViewById(R.id.videoContainerLayout);
mYouTubePlayerFragment = YouTubePlayerSupportFragment.newInstance();
return view;
}
viewHolder.videoButton = (FloatingActionButton) view.findViewById(R.id.videoButton);
viewHolder.videoButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view1) {
if (view.findViewById(R.id.videoContainer).isShown()) {
animateFab(false);
videoContainer.setVisibility(View.GONE);
} else {
if (context instanceof TestActivity)
((TestActivity) context).setAutoOrientationEnabled(true);
youTubeVideoInit(artWork.getVideo_uri(), view);
animateFab(true);
}
}
});
#Override
public void setUserVisibleHint(boolean isVisibleToUser) {
super.setUserVisibleHint(isVisibleToUser);
if (viewHolder != null) {
if (!isVisibleToUser ) {
isVisible = false;
if (videoContainer != null)
if (videoContainer.isShown()) {
viewHolder.videoButton.performClick();
}
if(mYouTubePlayerFragment!=null)
getChildFragmentManager().beginTransaction().detach(mYouTubePlayerFragment).commitAllowingStateLoss();
} else {
if(mYouTubePlayerFragment!=null)
getChildFragmentManager().beginTransaction().attach(mYouTubePlayerFragment).commitAllowingStateLoss();
isVisible = true;
}
}
}
YouTubePlayer mPlayer;
YouTubePlayerSupportFragment mYouTubePlayerFragment;
String youtubeID;
LinearLayout videoContainer;
public void youTubeVideoInit(String youtubeUrl, final View view) {
final String API_KEY = getString(R.string.develop_key);
Uri uri = Uri.parse(youtubeUrl);
try {
youtubeID = URLDecoder.decode(uri.getQueryParameter("v"), "UTF-8");
} catch (UnsupportedEncodingException exception) {
exception.printStackTrace();
}
mYouTubePlayerFragment.initialize(API_KEY, new YouTubePlayer.OnInitializedListener() {
#Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, final YouTubePlayer youTubePlayer, boolean isRejected) {
if (!isRejected) {
mPlayer = youTubePlayer;
mPlayer.cueVideo(youtubeID);
mPlayer.setOnFullscreenListener(new YouTubePlayer.OnFullscreenListener() {
#Override
public void onFullscreen(boolean b) {
if (!b && context instanceof TestActivity){
((TestActivity) context).setPortraitOrientation();
((TestActivity) context).setAutoOrientationEnabled(true);
}
}
});
}
}
#Override
public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult youTubeInitializationResult) {
}
});
getChildFragmentManager().beginTransaction().replace(R.id.videoContainer, mYouTubePlayerFragment, YouTubePlayerFragment.class.getSimpleName()).commit();
videoContainer.setVisibility(View.VISIBLE);
}
EDIT: I found what is the problem: The Zoom-out page transformer overlays the videos.

Related

Use only ExoPlayer's controller for playing audio in Android without the black preview

I want to play a list of audio files in android. As you might know, when you have video files, using the com.google.android.exoplayer2.ui.PlayerView does make sense because you can see the content of the video on the screen while you have the controller for play/pause etc. on the bottom.
But with audio files, you have a black screen if you let play the audio files.
What I need is to use only the controller without the black screen.
Is there a way to do that ?
1st EDIT:
In the documentation, I came across PlaybackControlView and PlayerControlView. Can I use them for my situation ? If yes, which one to use ?
2nd EDIT: Here are my results after 1 day of research. I used PlaybackControlView in my layout like this:
<com.google.android.exoplayer2.ui.PlaybackControlView
android:id="#+id/play_back_control_view"
android:layout_width="0dp" <--- I use ConstraintLayout, so this is okay
android:layout_height="wrap_content"
android:background="#color/black"
android:alpha="0.15"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:controller_layout_id="#layout/custom_playback_control_view" />
As you might see from the layout above, I use a custom layout for this called custom_playback_control_view.xml. Here is the my custom layout content:
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/black"
xmlns:tools="http://schemas.android.com/tools">
<ImageButton
android:id="#id/exo_play"
style="#style/ExoMediaButton.Play"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="ContentDescription"/>
<ImageButton android:id="#id/exo_pause"
style="#style/ExoMediaButton.Pause"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="ContentDescription"/>
<View
android:id="#id/exo_progress_placeholder"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="26dp"
app:layout_constraintEnd_toStartOf="#id/exo_duration"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toEndOf="#id/exo_play"/>
<TextView
android:id="#id/exo_duration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:includeFontPadding="false"
android:paddingLeft="4dp"
android:paddingRight="4dp"
android:textColor="#FFBEBEBE"
android:textSize="14sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#id/exo_progress_placeholder"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Last but not least, I attached the ExoPlayer to the PlaybackControlView like this in my Fragment:
myAudioPlayer = ExoPlayerFactory.newSimpleInstance(context)
binding.playBackControlView.player = myAudioPlayer
Try to create a custom controller like this and name it media_controller.xml. I used data binding in laout
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<FrameLayout
android:id="#+id/root"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#44000000"
android:focusableInTouchMode="false">
<RelativeLayout
android:id="#+id/controller"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp">
<ImageView
android:id="#+id/play"
android:layout_width="64dp"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:adjustViewBounds="true"
android:padding="2dp"
android:src="#mipmap/ic_media_play" />
<ImageView
android:id="#+id/forward"
android:layout_width="64dp"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toEndOf="#id/play"
android:adjustViewBounds="true"
android:clickable="true"
android:focusable="true"
android:padding="6dp"
android:src="#mipmap/ic_media_forward" />
<ImageView
android:id="#+id/backward"
android:layout_width="64dp"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toStartOf="#id/play"
android:adjustViewBounds="true"
android:clickable="true"
android:focusable="true"
android:padding="6dp"
android:src="#mipmap/ic_media_backward" />
</RelativeLayout>
</FrameLayout>
</layout>
Next create a custom class ExpoMediaController.java like following
public class ExpoMediaController extends FrameLayout implements View.OnClickListener, Player.EventListener{
private LayoutInflater inflater;
Player simpleExoPlayer;
private MediaControllerBinding binding;//media_controller.xml
public ExpoMediaController(Context context, AttributeSet attrs) {
super(context, attrs);
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
initView();
}
public ExpoMediaController(Context context) {
super(context);
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
initView();
}
private void initView() {
binding = DataBindingUtil.inflate(inflater, R.layout.media_controller, this, true);
binding.play.setOnClickListener(this);
binding.forward.setOnClickListener(this);
binding.backward.setOnClickListener(this);
}
//Use this method to set and unset the player
public void setPlayer(#Nullable Player simpleExoPlayer) {
if (this.simpleExoPlayer == simpleExoPlayer) {
return;
}
Player oldPlayer = this.simpleExoPlayer;//get reference of old player which attached previously
if (oldPlayer != null) {//if old player not null then clear it
oldPlayer.removeListener(this);
}
this.simpleExoPlayer = simpleExoPlayer;
if (this.simpleExoPlayer != null) {
this.simpleExoPlayer.addListener(this);
}
}
#Override
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
switch (playbackState) {
case STATE_BUFFERING:
break;
case STATE_ENDED:
break;
case STATE_IDLE:
break;
case STATE_READY:
if (playWhenReady) {
binding.play.setImageResource(R.mipmap.ic_media_pause);
binding.play.setVisibility(VISIBLE);
} else {
binding.play.setImageResource(R.mipmap.ic_media_play);
binding.play.setVisibility(VISIBLE);
}
break;
default:
break;
}
}
#Override
public void onClick(View v) {
if (v == binding.play && simpleExoPlayer != null) {
if (simpleExoPlayer.isPlaying()) {
simpleExoPlayer.setPlayWhenReady(false);
showControls();
} else {
if (simpleExoPlayer.getPlaybackState() == STATE_ENDED) {
simpleExoPlayer.seekTo(0);
}
simpleExoPlayer.setPlayWhenReady(true);
}
}
}}
Use ExpoMediaController in your activity layout replacing com.google.android.exoplayer2.ui.PlaybackControlView. Then call setPlayer method of ExpoMediaController. Now you have total control over controller view.

Shared Elements Transitions only working in 2/3 cases

I was playing around with the Shared Element Transition and developed a testapp with 4 Fragments.
In the picture you can see, the first Fragment contains a "start now" message, when it's clicked I want to replace the container with the Fragment in the middle. As an eye candy I want an Animation by using Shared Element Transitions.
Problem
My Problem is, if I leave the first Fragment empty (without starting message) and I for example set the OnClickListener to the Icon itself, everything is working alright with a nice animation. But if the first Fragment has that message in it only the first Icon (the second Fragment, picture in mid) doesn't have an animation anymore. It's just replacing the first fragment. The curios thing is, if I change my OnClickListener and let it start the second page (right picture) the animation is working fine again. So only the first/left Icon does not provide an animation though all Methods and XML are mostly 1:1 the same.
As I couldn't develope a better solution, each "toolbar" is designed in the Fragment itself.
Main Activity
public class FirstStartupActivity extends AppCompatActivity {
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_firststartup);
doFragmentTransaction(new MainFragment(), "TAG", false, null);
}
public void doFragmentTransaction(Fragment fragment, String tag, boolean addToBackStack, List<View> sharedElements){
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.ActivityFirstStartup_fragmentContainer, fragment, tag);
if(addToBackStack){
transaction.addToBackStack(tag);
}
if( sharedElements != null && !sharedElements.isEmpty()){
for(int i = 0; i < sharedElements.size(); i++){
View view = sharedElements.get(i);
transaction.addSharedElement(view, view.getTransitionName());
}
}
transaction.commit();
}}
First Fragment with Message
public class MainFragment extends Fragment {
#Nullable
#Override
public View onCreateView(#NonNull LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_firststartup_home, container, false);
View view = v.findViewById(R.id.relLayoutPageOne);
final List<View> listview = new ArrayList<>();
listview.add(view);
View view2 = v.findViewById(R.id.relLayoutPageTwo);
final List<View> listview2 = new ArrayList<>();
listview2.add(view2);
Button button = v.findViewById(R.id.buttonStart);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
((FirstStartupActivity)getActivity()).doFragmentTransaction(new UsernameFragment(), "test", true, listview);
//((FirstStartupActivity)getActivity()).doFragmentTransaction(new CameraFragment(), "TEST2", true, listview2);
}
});
RelativeLayout rel2 = v.findViewById(R.id.relLayoutPageTwo);
rel2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
((FirstStartupActivity)getActivity()).doFragmentTransaction(new CameraFragment(), "TEST2", true, listview2);
}
});
return v;
}}
Second Fragment No Animation
public class UsernameFragment extends Fragment {
#Nullable
#Override
public View onCreateView(#NonNull LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_firststartup_pgone, container, false);
postponeEnterTransition();
return v;
}
#Override
public void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){
setSharedElementEnterTransition(TransitionInflater.from(getContext()).inflateTransition(android.R.transition.move));
}
}}
Third Fragment Working
public class CameraFragment extends Fragment {
#Nullable
#Override
public View onCreateView(#NonNull LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_firststartup_pgtwo, container, false);
return v;
}
#Override
public void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){
setSharedElementEnterTransition(TransitionInflater.from(getContext()).inflateTransition(android.R.transition.move));
}
}}
Second Fragment (Picture in middle) No Animation when replacing)
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.constraint.ConstraintLayout
android:id="#+id/constraintLayout2"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#drawable/draw_login_edittext">
</android.support.constraint.ConstraintLayout>
<RelativeLayout
android:id="#+id/relLayoutPageTwo"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_marginTop="4dp"
android:background="#drawable/draw_login_edittext_rounded"
android:transitionName="ProfileCam"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageView
android:transitionName="ProfileCam"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="fitStart"
app:srcCompat="#mipmap/testtwo" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/relLayoutPageThree"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:background="#drawable/draw_login_edittext_rounded"
android:transitionName="ProfileGender"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.95"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="fitStart"
app:srcCompat="#mipmap/testthree" />
</RelativeLayout>
<RelativeLayout
android:transitionName="ProfilePic"
android:layout_width="273dp"
android:layout_height="210dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:background="#drawable/draw_login_edittext_rounded"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/constraintLayout2">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="fitStart"
app:srcCompat="#mipmap/test" />
</RelativeLayout>
First Fragment (Picture left)
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.constraint.ConstraintLayout
android:id="#+id/constraintLayout2"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#a8655c">
</android.support.constraint.ConstraintLayout>
<RelativeLayout
android:transitionName="ProfilePic"
android:id="#+id/relLayoutPageOne"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:background="#drawable/draw_login_edittext_rounded"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.049"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="fitStart"
app:srcCompat="#mipmap/test" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/relLayoutPageTwo"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:background="#drawable/draw_login_edittext_rounded"
android:transitionName="ProfileCam"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="fitStart"
app:srcCompat="#mipmap/testtwo" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/relLayoutPageThree"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:background="#drawable/draw_login_edittext_rounded"
android:transitionName="ProfileGender"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.95"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="fitStart"
app:srcCompat="#mipmap/testthree" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:forceHasOverlappingRendering="true"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:background="#drawable/draw_login_edittext_rounded"
android:padding="25dp"
android:transitionName="ProfilePic"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/constraintLayout2">
<TextView
android:id="#+id/text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text="Bevor du loslegen könnst benötigen wir noch kurz ein paar Informationen über dich! :)"
android:textAlignment="center"
android:textColor="#BFFFFFFF" />
<Button
android:id="#+id/buttonStart"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/text"
android:layout_centerHorizontal="true"
android:layout_marginHorizontal="15dp"
android:layout_marginTop="15dp"
android:background="#drawable/draw_rounded_edittext_dark"
android:text="Start now"
android:textColor="#BFFFFFFF" />
</RelativeLayout>
Third Fragment (right Picture) Animation when replacing
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.constraint.ConstraintLayout
android:id="#+id/constraintLayout2"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#drawable/draw_login_edittext">
</android.support.constraint.ConstraintLayout>
<RelativeLayout
android:id="#+id/relLayoutPageOne"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:background="#drawable/draw_login_edittext_rounded"
android:transitionName="ProfilePic"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.049"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageView
android:id="#+id/imageView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="fitStart"
app:srcCompat="#mipmap/test" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/relLayoutPageThree"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:background="#drawable/draw_login_edittext_rounded"
android:transitionName="ProfileGender"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.95"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="fitStart"
app:srcCompat="#mipmap/testthree" />
</RelativeLayout>
<RelativeLayout
android:layout_width="273dp"
android:layout_height="210dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:background="#c8c8c8"
android:transitionName="ProfileCam"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/constraintLayout2">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="fitStart"
app:srcCompat="#mipmap/testtwo" />
</RelativeLayout>
Visual Description
First Icon doesn't work but the second one works like charm
For some Reason the first GIF is way too fast, its popping up normally the only Problem is the missing Animation
Well I tried to change some things and I made everything worse. Then I "repaired" it and now it works, unfortunetly I can't show you a solution for that. I try to work through the codes again
EDIT: #LieForBanana had the solution but I understood him wrong, indeed my first Fragment also had the Transition Name it (3x TransitionName ProfilePic). I am ashamed, it was just one silly mistake

RecyclerView is lagging in scroll

I have three RecyclerViews, and all three are lagging in scroll. I have tried many things suggested on the internet, but nothing made my RecyclerView faster.
I have tried the solutions given below,
RecyclerView laggy scrolling
Extremely Laggy RecyclerView Performance
Lags when RecyclerView scrolling
And some more. Some of them are not relevant. But still, it lags.
For the reference, below are the images for RecyclerView items.
The xml of the view (for the single chat bubble). It's almost same as WhatsApp.
<LinearLayout
android:id="#+id/transactionOut"
android:layout_width="#dimen/dp300"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="gone"
android:layout_gravity="end"
android:paddingStart="0dp"
android:paddingLeft="0dp"
android:paddingEnd="13dp"
android:paddingRight="13dp"
android:clickable="true"
android:background="#drawable/outgoing_chat_bubble">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:minWidth="#dimen/dp100"
android:orientation="horizontal"
android:elevation="#dimen/general_margin_or_padding_very_small"
android:padding="#dimen/dp10">
<ImageView
android:id="#+id/transactionImageOut"
android:layout_margin="#dimen/dp4"
android:layout_width="#dimen/size_transaction"
android:layout_height="#dimen/size_transaction"
android:padding="3dp"
android:visibility="gone"
android:src="#drawable/ic_transaction_indication_sent"
android:layout_gravity="center_vertical"
android:contentDescription="#string/payment_sent"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="4dp"
android:layout_marginRight="4dp"
android:gravity="center"
android:textSize="#dimen/general_for_all"
android:text="–"
android:textColor="#color/app_font_detail_color"/>
<style.views.CustomTextView
android:id="#+id/transactionAmountOut"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/progress_loading"
android:textColor="#color/app_font_detail_color"
android:layout_marginLeft="#dimen/dp4"
android:layout_marginStart="#dimen/dp4"
android:ellipsize="end"
android:maxLines="1"
android:textSize="#dimen/general_for_all"
appUI:font="#string/appNormalFontName"/>
</LinearLayout>
<View
android:id="#+id/separatorMessageOut"
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:visibility="gone"
android:layout_marginStart="#dimen/general_margin_or_padding_very_small"
android:layout_marginEnd="#dimen/general_margin_or_padding_very_small"
android:layout_marginRight="#dimen/general_margin_or_padding_very_small"
android:layout_marginLeft="#dimen/general_margin_or_padding_very_small"
android:background="#color/app_font_detail_color"/>
<LinearLayout
android:id="#+id/layoutMessageOut"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="top"
android:visibility="gone"
android:paddingTop="#dimen/general_margin_or_padding_very_small"
android:paddingBottom="#dimen/general_margin_or_padding_very_small">
<ImageView
android:layout_width="#dimen/size_extra_icon"
android:layout_height="#dimen/size_extra_icon"
android:layout_marginTop="#dimen/icon_margin_top"
android:src="#drawable/ic_sms"
android:layout_marginStart="#dimen/general_margin_or_padding_small"
android:layout_marginLeft="#dimen/general_margin_or_padding_small"
android:visibility="visible"
android:contentDescription="#string/design"/>
<TextView
android:id="#+id/textMessageOut"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/general_margin_or_padding_very_small"
android:layout_marginLeft="#dimen/general_margin_or_padding_very_small"
android:textColor="#color/app_font_detail_color"
android:text="Text message"/>
</LinearLayout>
<View
android:id="#+id/separatorNoteOut"
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:visibility="gone"
android:layout_marginStart="#dimen/general_margin_or_padding_very_small"
android:layout_marginEnd="#dimen/general_margin_or_padding_very_small"
android:layout_marginRight="#dimen/general_margin_or_padding_very_small"
android:layout_marginLeft="#dimen/general_margin_or_padding_very_small"
android:background="#color/app_font_detail_color"/>
<LinearLayout
android:id="#+id/layoutNoteOut"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="top"
android:visibility="gone"
android:paddingTop="#dimen/general_margin_or_padding_very_small"
android:paddingBottom="#dimen/general_margin_or_padding_very_small">
<ImageView
android:layout_width="#dimen/size_extra_icon"
android:layout_height="#dimen/size_extra_icon"
android:layout_marginTop="#dimen/icon_margin_top"
android:src="#drawable/ic_notes"
android:layout_marginStart="#dimen/general_margin_or_padding_small"
android:layout_marginLeft="#dimen/general_margin_or_padding_small"
android:visibility="visible"
android:contentDescription="#string/design"/>
<TextView
android:id="#+id/textNoteOut"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/general_margin_or_padding_very_small"
android:layout_marginLeft="#dimen/general_margin_or_padding_very_small"
android:textColor="#color/app_font_detail_color"
android:text="Text note"/>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:background="#color/app_font_detail_color"
android:layout_marginStart="#dimen/general_margin_or_padding_very_small"
android:layout_marginEnd="#dimen/general_margin_or_padding_very_small"
android:layout_marginRight="#dimen/general_margin_or_padding_very_small"
android:layout_marginLeft="#dimen/general_margin_or_padding_very_small"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="#dimen/dp6">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="start|center_vertical">
<style.views.CircleImageView
android:id="#+id/bankLogoOut"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_gravity="center_vertical"
android:src="#drawable/placeholder_default"
appUI:circular_border_color="#color/profile_border_color"
appUI:circular_border_width="#dimen/dp1" />
<TextView
android:id="#+id/bankNameOut"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/general_margin_or_padding_very_small"
android:layout_marginLeft="#dimen/general_margin_or_padding_very_small"
android:maxLines="1"
android:ellipsize="end"
android:text="#string/progress_loading"
android:textSize="#dimen/small_size" />
</LinearLayout>
<ImageView
android:id="#+id/showDetailImageOut"
android:layout_width="0dp"
android:layout_weight="0.5"
android:layout_height="wrap_content"
android:layout_marginRight="#dimen/dp4"
android:layout_marginEnd="#dimen/dp4"
android:src="#drawable/ic_transaction_more"
android:contentDescription="#string/more"/>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<ImageView
android:id="#+id/messageStatusImageOut"
android:layout_width="#dimen/size_transaction"
android:layout_height="#dimen/size_transaction"
android:layout_centerVertical="true"
android:src="#drawable/ic_pending"
android:layout_marginStart="#dimen/general_margin_or_padding_small"
android:layout_marginLeft="#dimen/general_margin_or_padding_small"
android:visibility="visible"
android:contentDescription="#string/design"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"/>
<style.views.CustomTextView
android:id="#+id/transactionDatetimeOut"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:gravity="end"
android:text="#string/account"
android:textColor="#color/app_font_detail_color"
android:textSize="#dimen/date_time_stamp"
android:layout_toLeftOf="#+id/messageStatusImageOut"
android:layout_toStartOf="#+id/messageStatusImageOut" />
</RelativeLayout>
</LinearLayout>
</LinearLayout>
Here is it's adapter
#Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
holder.setIsRecyclable(false);
if (holder instanceof HeaderViewHolder) {
HeaderViewHolder transactionViewHolder = (HeaderViewHolder) holder;
String getTodayDate = (String) filteredList.get(position);
transactionViewHolder.setDate(DateUtility.getFormattedDate(getTodayDate));
} else if (holder instanceof MainViewHolder) {
MainViewHolder viewHolder = (MainViewHolder) holder;
try {
final History history = (History) filteredList.get(position);
viewHolder.setTransaction(history, mContext);
} catch (Exception e){
e.printStackTrace();
}
}
}
And the setTransaction method of ViewHolder
private void setTransaction(final History history, final Context context){
String myId = new Session(context).getStringForKey(Session.prIdKey);
if(history.getTo().equals(history.getFrom())) {
transactionSelf.setVisibility(View.VISIBLE);
transactionOut.setVisibility(View.GONE);
transactionIn.setVisibility(View.GONE);
transactionAmountSelf.setText(Utils.parseIntoPKR(history.getAmount()));
transactionDateTimeSelf.setText(DateUtility.getTimeFromEpoch(history.getEpoch()));
messageStatusImageSelf.setVisibility(View.VISIBLE);
switch (history.getStatus()) {
case Constants.STATUS_PENDING:
messageStatusImageSelf.setImageResource(R.drawable.ic_pending);
break;
case Constants.STATUS_FAILED:
messageStatusImageSelf.setImageResource(R.drawable.ic_transaction_status_blocked);
break;
default:
messageStatusImageSelf.setImageResource(R.drawable.ic_transaction_status_done);
break;
}
LinkedBank associatedBank = history.getSenderBank();
bankNameSelf.setText(associatedBank.fetchAbbreviationAndAccountNumber());
if(history.getReceiverNotes() != null && history.getReceiverNotes().length() > 0) {
separatorNoteSelf.setVisibility(View.VISIBLE);
layoutNoteSelf.setVisibility(View.VISIBLE);
textNoteSelf.setText(history.getReceiverNotes());
} else if(history.getSenderNotes() != null && history.getSenderNotes().length() > 0) {
separatorNoteSelf.setVisibility(View.VISIBLE);
layoutNoteSelf.setVisibility(View.VISIBLE);
textNoteSelf.setText(history.getSenderNotes());
}
transactionSelf.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
((OnIndividualTransactionSelection) context).onTransactionSelected(history);
}
});
} else if(history.getFrom().equals(myId)) {
//from my number -> cash out
transactionOut.setVisibility(View.VISIBLE);
transactionIn.setVisibility(View.GONE);
transactionSelf.setVisibility(View.GONE);
if(history.getMessage() != null && history.getMessage().length() > 0) {
separatorMessageOut.setVisibility(View.VISIBLE);
layoutMessageOut.setVisibility(View.VISIBLE);
textMessageOut.setText(history.getMessage());
}
if(history.getSenderNotes() != null && history.getSenderNotes().length() > 0) {
separatorNoteOut.setVisibility(View.VISIBLE);
layoutNoteOut.setVisibility(View.VISIBLE);
textNoteOut.setText(history.getSenderNotes());
}
messageStatusImageOut.setVisibility(View.VISIBLE);
switch (history.getStatus()) {
case Constants.STATUS_PENDING:
messageStatusImageOut.setImageResource(R.drawable.ic_pending);
break;
case Constants.STATUS_FAILED:
messageStatusImageOut.setImageResource(R.drawable.ic_transaction_status_blocked);
break;
default:
messageStatusImageOut.setImageResource(R.drawable.ic_transaction_status_done);
break;
}
transactionAmountOut.setText(Utils.parseIntoPKR(history.getAmount()));
transactionDatetimeOut.setText(DateUtility.getTimeFromEpoch(history.getEpoch()));
LinkedBank associatedBank = history.getSenderBank();
bankNameOut.setText(associatedBank.fetchAbbreviationAndAccountNumber());
Picasso.with(context).load(associatedBank.getBankLogo()).placeholder(R.drawable.placeholder_default).error(R.drawable.placeholder_default).into(bankLogoOut);
transactionOut.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
((OnIndividualTransactionSelection) context).onTransactionSelected(history);
}
});
} else if(history.getTo().equals(myId)) {
transactionIn.setVisibility(View.VISIBLE);
transactionOut.setVisibility(View.GONE);
transactionSelf.setVisibility(View.GONE);
if(history.getMessage() != null && history.getMessage().length() > 0) {
separatorMessageIn.setVisibility(View.VISIBLE);
layoutMessageIn.setVisibility(View.VISIBLE);
textMessageIn.setText(history.getMessage());
}
if(history.getReceiverNotes() != null && history.getReceiverNotes().length() > 0) {
separatorNoteIn.setVisibility(View.VISIBLE);
layoutNoteIn.setVisibility(View.VISIBLE);
textNoteIn.setText(history.getReceiverNotes());
}
transactionAmountIn.setText(Utils.parseIntoPKR(history.getAmount()));
transactionDatetimeIn.setText(DateUtility.getTimeFromEpoch(history.getEpoch()));
LinkedBank associatedBank = history.getReceiverBank();
bankNameIn.setText(associatedBank.fetchAbbreviationAndAccountNumber());
Picasso.with(context).load(associatedBank.getBankLogo()).placeholder(R.drawable.placeholder_default).error(R.drawable.placeholder_default).into(bankLogoIn);
transactionIn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
((OnIndividualTransactionSelection) context).onTransactionSelected(history);
}
});
}
}
It's answer may help me to optimize the other two RecyclerViews as well. Any help is highly appreciated.
Two quick tips
1) You might want to cut down on a lots o processing while it's still scrolling. This will improve scrolling performance substantially
2) You might want to relook at this and similar 'new' later, allocating on every bind will slow down your scroll.
String myId = new Session(context).getStringForKey(Session.prIdKey);

How to delete space when I hide a CardView

How can I delete the space when I hide a CardView? I doing an app with android and Firebase and I show the information from firebase in cardviews, but when the info isn't correct the cardview must disappear. The point is that the cardview disappear, but still uses a space in the layout, I've tried the answers in
setVisibility(GONE) view becomes invisible but still occupies space But it doesn't work for me.
#Override
protected void onStart() {
super.onStart();
firebaseAuth.addAuthStateListener(firebaseAuthListener);
final FirebaseRecyclerAdapter<CursosDB, MainActivity.CursosPViewHolder> firebaseRecyclerAdapter =
new FirebaseRecyclerAdapter<CursosDB, MainActivity.CursosPViewHolder>(
CursosDB.class,
R.layout.design_row_cursos,
MainActivity.CursosPViewHolder.class,
myRef)
{
#Override
protected void populateViewHolder(MainActivity.CursosPViewHolder viewHolder, final CursosDB Cmodel, int position)
{
String estado = Cmodel.getSTATUS().toString();
if (estado.equals("OK")){
viewHolder.setPhotoURL(getApplicationContext(), Cmodel.getURI());
viewHolder.setTitle(Cmodel.getTITLE());
viewHolder.setCiudad(Cmodel.getPLACE());
viewHolder.setLevel(Cmodel.getLEVEL());
viewHolder.setDur(Cmodel.getDURACION());
viewHolder.setPrice(Cmodel.getCOSTO());
}else{
RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) viewHolder.mView.getLayoutParams();
layoutParams.setMargins(0,0,0,0);
viewHolder.mView.setLayoutParams(layoutParams);
viewHolder.mView.setVisibility(View.INVISIBLE);
viewHolder.mView.setVisibility(View.GONE);
//viewHolder.mView.setVisibility(View.GONE);
//Toast.makeText(getApplicationContext(), "Ningún curso aprobado aún", Toast.LENGTH_SHORT).show();
}
viewHolder.mView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// Toast.makeText(getApplicationContext(), Cmodel.getUSERID(), Toast.LENGTH_LONG).show();
//Toast.makeText(getApplicationContext(), Cmodel.getTITLE(), Toast.LENGTH_SHORT).show();
//Toast.makeText(UsersList.this, user_key, Toast.LENGTH_LONG).show();
}
});
}
};
mCourses.setAdapter(firebaseRecyclerAdapter);
}
This is my layout:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/cardview_cursos"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:onClick="positionAction"
android:padding="4dp"
android:paddingBottom="4dp"
android:paddingEnd="4dp"
android:paddingStart="4dp"
android:paddingTop="4dp"
app:cardElevation="4dp">
<LinearLayout android:id="#+id/layout_to_hide"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/Cimg"
android:layout_width="match_parent"
android:layout_height="165dp"
android:scaleType="center"
app:srcCompat="#drawable/knowit_logo" />
<TextView
android:id="#+id/Ctitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/Cimg"
android:layout_marginLeft="14dp"
android:layout_marginStart="14dp"
android:paddingTop="8dp"
android:text="Titulo"
android:textStyle="bold" />
<TextView
android:id="#+id/Clugar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/Ctitle"
android:layout_alignStart="#+id/Ctitle"
android:layout_below="#+id/Ctitle"
android:layout_marginTop="10dp"
android:text="Lugar" />
<TextView
android:id="#+id/textView29"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/Clugar"
android:layout_alignStart="#+id/Clugar"
android:layout_below="#+id/Clugar"
android:layout_marginTop="10dp"
android:text="$" />
<TextView
android:id="#+id/Cprice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/textView29"
android:layout_marginBottom="4dp"
android:layout_toEndOf="#+id/textView29"
android:layout_toRightOf="#+id/textView29"
android:paddingLeft="5dp"
android:text="0.0" />
<TextView
android:id="#+id/Cdur"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/Clugar"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginEnd="126dp"
android:layout_marginRight="126dp"
android:text="Duración" />
<TextView
android:id="#+id/Cnivel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/Cprice"
android:layout_alignLeft="#+id/Cdur"
android:layout_alignStart="#+id/Cdur"
android:layout_marginBottom="0dp"
android:text="Nivel" />
</RelativeLayout>
</LinearLayout> </android.support.v7.widget.CardView>
This is the mView:
public static class CursosPViewHolder extends RecyclerView.ViewHolder {
View mView;
public CursosPViewHolder(final View itemView) {
super(itemView);
mView = itemView;
}
public void setTitle(String title){
TextView post_title = (TextView)mView.findViewById(R.id.Ctitle);
post_title.setText(title);
}
public void setCiudad (String ciudad){
TextView post_city = (TextView)mView.findViewById(R.id.Clugar);
post_city.setText(ciudad);
}
public void setPhotoURL(Context ctx, String pgotouserurl) {
ImageView post_image =(ImageView)mView.findViewById(R.id.Cimg);
Picasso.with(ctx).load(pgotouserurl).into(post_image);
} }
I hope you can help me.
First the XML code you've posted ils wrong closed,(must finish with a CardView tag)
On addition be sure you're pointing the CardView layout with mView field ans Only use GONE or INVISIBLE,
INVISIBLE change your Panel ( Root view ) structure but GONE don't

Android content of ViewGroup disappears when rotationY is animated

I created an animation that flips a "card" to its backside.
To achieve this, I used setRotationYBy() and setVisibility() on each, the front, and the back.
The animation itself works fine, but when the animation is running, the content of both cards disappears (and reappears when the animation is finished).
cardFront.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
final Runnable moveMapDown = new Runnable() {
public void run() {
map.animate().y(0);
}
};
final Runnable flipCard2 = new Runnable() {
public void run() {
cardBack.setVisibility(View.VISIBLE);
cardFront.setVisibility(View.INVISIBLE);
currentFront = false;
CardBack.animate().rotationYBy(90).setInterpolator
(new DecelerateInterpolator()).withEndAction(moveMapDown).setDuration(300);
cardFront.setRotationY(180);
}
};
Runnable flipCard = new Runnable() {
public void run() {
cardBack.setRotationY(-90);
cardFront.animate().rotationYBy(90).setInterpolator
(new AccelerateInterpolator()).withEndAction(flipCard2).setDuration(300);
}
};
map.animate().y(-200).withEndAction(flipCard);
}
});
XML-Layout of the backside (front almost the same).
<RelativeLayout
android:id="#+id/back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/imageView1"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:layout_centerVertical="true"
android:layout_marginTop="-18dp"
android:background="#drawable/bgpatch"
android:paddingBottom="16dp"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:paddingTop="6dp"
android:visibility="invisible" >
<RelativeLayout
android:layout_width="300dp"
android:layout_height="288dp"
android:background="#drawable/dayplan_element_bg" >
<RelativeLayout
android:id="#+id/background"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/dayplan_element_bg"
android:paddingBottom="2dp"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:paddingTop="2dp" >
<TextView
android:id="#+id/backTitle"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:layout_centerVertical="true"
android:gravity="center"
android:text="zusätzliche Informationen"
android:textAppearance="?android:textAppearanceLarge"
android:textColor="#android:color/primary_text_dark"
android:textSize="30sp"
android:textStyle="italic" />
</RelativeLayout>
<View
android:id="#+id/view1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="-1dp"
android:background="#drawable/shadow" />
</RelativeLayout>
</RelativeLayout>
Found the solution:
I had hardware-acceleration set to false due to another part of the app that requires this.
Set it back to true and it works!

Categories

Resources