I have an ImageView in a ViewPager2, the ViewPager2 uses a ConstraintLayout to organize all its elements into place. It takes a sec for the image to load in causing for the ViewPager2 height to fluctuate. I can use a transparent placeholder image that is statically sized but depending on the screen size I want this image to adjust to fit the screen appropriately so again I run into the height fluctuating.
I've tried to use a LinearLayout and RelativeLayout, but the tradeoff of these is that they don't handle the other dynamic content that loads right away neatly.
Any recommendations for how to solve this issue is appreciated. My guess is that if I can know when the image is loaded in or when it is ready to be loaded in via URL then I could pause on displaying information in the ViewPager2 until all the information is ready.
I also use a progress bar that is not attached to the image being loaded so the progress bar is always displayed. Knowing if the image has loaded in will allow me to set the progress bar's visibility to GONE programmatically, but this isn't too much of a problem since it is covered by the image anyways.
There are buttons from the service. I need to show these buttons according to the screen size. Buttons that do not fit on the screen should appear when you scroll to the right using the viewpager. How can I do that.
Sorry, I made the picture by hand.
I have an Activity that contains a FrameLayout where ExoPlayer takes place.
This activity support both orientations and video aspect ratio should be preserved.
According to ExoPlayer docs, for the setResizeMode we can have one of the following:
RESIZE_MODE_FIT,
RESIZE_MODE_FIXED_WIDTH,
RESIZE_MODE_FIXED_HEIGHT,
RESIZE_MODE_FILL,
RESIZE_MODE_ZOOM
In my case, since I don't know the video size nor the device orientation, I can have two scenarios:
Video is larger than my Viewport, so I would like to have RESIZE_MODE_FIT to scale it down
Video is smaller than my Viewport, so I would like to have RESIZE_MODE_ZOOM to scale it up.
But in the end I could not find a way to achieve this behavior.
If I set RESIZE_MODE_FIT, small videos does not fill my Viewport.
If I set RESIZE_MODE_ZOOM, large videos overflow the Viewport.
Thanks.
I am testing ExoPlayer2 using the google exoplayer-codelab-00 app https://github.com/googlecodelabs/exoplayer-intro . The goal is streaming from an IP camera. I have to rotate the camera video stream from landscape to portrait, shown on device in portrait mode.
I changed surface type to TextureView, in PlayerActivity.initializePlayer set playerView.setRotation(90). The video appears correctly rotated, but it is scaled at the initial size which would have been shown without the rotation, like this.
I tried changing width and height in playerView.getLayoutParams() + playerView.setLayoutParams(), but the video is never shown higher. Change of RESIZE_MODE_FIT to RESIZE_MODE_FILL just expands the video to fit the new width, but the height is not changed, like this.
Setting player.setVideoScalingMode(C.VIDEO_SCALING_MODE_SCALE_TO_FIT) makes no difference either.
IMO some layer of the view stack does not get rotated with the playerView.setRotation(90) and the unrotated dimensions somehow constrain the rotated video. I want the rotation fixed, it is called before setting media item. The device will always be positioned in portrait mode (fixed installation). Thanks a lot for any hints, I am completely new to Android.
I am trying to play a videoview on top of another video view. The first video view is paused, while the second is playing. It appears to work but no second video appears on the screen (though I hear the audio and see the controls that would normally appear on top). I am assuming this is some sort of order issue. Any thoughts. By the way, I have no problem displaying other views on top of the main video view and having the video fill the background.
That won't work - the VideoView is special in the sense that it 'punches' a hole in the normal Views to allow direct access to the display pixels (or, in android terms, the 'Surface' - VideoView is a subclass of SurfaceView). You cannot layer two SurfaceViews on top of eachother - the first one that grabs the pixels (the Surface) will 'own' it. (see SurfaceHolder.Callback.surfaceCreated() / surfaceDestroyed())
Other Views on top of a SurfaceView do work, because the framework will compose the display bits of normal Views on top of the Surface. It cannot do that with another VideoView (i.e. a SurfaceView) because there is nothing to compose.
<VideoView android:id="#+id/videoView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<VideoView android:id="#+id/videoView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
when videoView2 starts playing setvisibilty of videoView1 invisible.
then you can make it visible when you need.
Use Thread to control both video
I don't know if this is helpful at the moment, but I managed to get something similar to what you want...
I needed to nest a VideoView on top of a SurfaceView; as long as they don't overlap 100% it can work. (what i mean is, my surfaceview is the whole screen and videoview is just a small portion of the screen)
The thing is - since you can't compose SurfaceViews, the first one to grab the pixels is the one that will be shown. Intuitiveness will drive you to Z-order your prioritized view AFTER the less-important one in the XML - but as I've said previously, the first one to grab the pixels stays, so make sure you define the smaller view FIRST, and then overlay it with the bigger one.
This will result in such behaviour that the smaller (in my case preview view) acquires the said X * Y pixels, and then the 'background' surfaceview (which is supposed to be on top of it according to the XML) takes up the rest and ignores the smaller surface.
I'm not too sure about handling events from those two though as I only have to play streams in those two views and not react to any kind of clicks/events generated by those two components, but it might be expected that if you followed this route - the bigger view will intercept all clicks made in the smaller view area (because it's on top according to the XML) so maybe you have to programatically move it on top as well upon creation.
Hope it helps.
EDIT:
Although... it like it just works once. It's a work in progress really. Upon returning from any activity, there's nothing i can do to prevent the bigger view claiming everything :/
you can add videoview a on top videoview b,like this,
parentview.removeview(a);
parentview.removviewe(b);
parentview.addview(a);
parentview.addview(b);
parentview.invalidate();
Ti's work for me. I hope it can helps.