android VideoView resizes video - android

I have a custom VideoView, I'm overriding onMeasure method to make video fill the screen, while keeping proportions of the video file.
Everything works fine, but with some videos, it has a strange behaviour:
I put an interrupt point in onMeasure method and run in debug mode.
When video loads, it fills the screen as expected, but after some seconds, exactly when the mouse pointer disappears, the video resizes to its original size, not filling the screen, and without passing again over the interrupt point (onMeasure method is not called).
If I move the mouse again, the video fills the screen until the pointer disappears.
I'm using Android 4.4.4.

In case someone has the same problem, I'll post what I did:
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getRealMetrics(metrics);
FrameLayout fralayout = (FrameLayout) findViewById(R.id.framelayoutparent);
FrameLayout.LayoutParams lpFraParams = (FrameLayout.LayoutParams) fralayout.getLayoutParams();
lpFraParams.width = metrics.widthPixels-1;
lpFraParams.height = metrics.heightPixels-1;
fralayout.setLayoutParams(lpFraParams);
Previously I didn't substract one pixel to width and height, substracting one pixel did the trick. This FrameLayout is the parent of the VideoView.
I don't understand why it had that behaviour.

Related

Changing the layout of SurfaceView on nVIdia Shield turns the screen black

I am rendering a video on a SurfaceView in my android app, and I want to resize the surface to match the video size. I do this by setting a new Layout like so:
FrameLayout.LayoutParams videoLayout = new FrameLayout.LayoutParams(width, height);
videoLayout.leftMargin = x;
videoLayout.topMargin = y;
view.setLayoutParams(videoLayout);
Seems to work fine on other android tv boxes but on nVidia Shield the screen goes black. It only works if width and height match the actual resolution, for anything other it's just black.
Also works if I render on a TextureView, but then I take a big performance hit.
Also tried with setFixedSize, same outcome.
view.getHolder().setFixedSize(width, height);

Android ViewPropertyAnimator silently fails alpha animations on large views

I have a list view that is populated with data from a web request. While waiting for the response I overlay another view on top (mNoDataLayout) with a progress bar and other information telling the user the data is coming. Once the data arrives I want to fade out the overlay view to reveal the populated list view:
mNoDataLayout.animate().setDuration(300).alpha(0.f);
The problem is this animation doesn't always run. Sometimes is works, sometimes it doesn't.
The fix was to set the height of my overlay view mNoDataLayout to the screen height. Previously I had it set to match_parent which meant that when lots of list data arrived, the list view could be very large, which caused the overlay view to be very large.
Once I set my overlay view to be smaller, the alpha animation started working without any other changes.
Perhaps Android is silently killing alpha animations on very large views in order to optimise rendering fill rate. But since those pixels are offscreen anyway, this probably implies it's also not doing any scissoring / culling, which seems odd.
DisplayMetrics displayMetrics = getActivity().getResources().getDisplayMetrics();
ViewGroup.LayoutParams layoutParams = mNoDataLayout.getLayoutParams();
layoutParams.height = displayMetrics.heightPixels;
mNoDataLayout.setLayoutParams(layoutParams);
This was on a Samsung Galaxy Note 4.

GLSurfaceView overlaps other views

I've got a programmatically-created layout, where when my app gets ads, it'll show an admob view, pushing my existing GLView down and resizing it.
However, although it initially seems to be pushing my GLView down, the GLView suddenly resets itself and overlaps the AdMob view and resets itself to its original size.
This is what I do to resize and reposition the GLSurfaceView:
Main.Instance.admobView.setVisibility(View.VISIBLE);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(Main.Instance.GLView.getWidth(),
Main.Instance.GLView.getHeight() - AdSize.BANNER.getHeight());
params.topMargin = AdSize.BANNER.getHeight();
Main.Instance.GLView.setLayoutParams(params);
Main.Instance.TopView.requestLayout();
This is what I get in the end:
http://i.stack.imgur.com/UuwKA.png
Does anyone have any idea what could be causing this?

Screen Size Honeycomb Menu android

Hi I am trying yo get the screen size of screen minus the menu bar at the bottom.
I know I could just subtract a constant number according to the resolution of the device but it is a super ugly hack. I am sure google people are not dumb enough to forget to give the user a function to get the height of the bottom menu bar so I can subtract it from the full screen size
This is a similar post.
Size of android notification bar and title bar?
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
what_i_need =metrics.heightPixels-buttomMenuHeight();
I need buttomMenuHeight();
i could not find it in the API. I don't really care about the backward comparability at this point
Thanks
Why not use the height of the activity's top-level View? e.g. if your activity contains a full-height LinearLayout, use its height, so you don't have to know the menu height, or noticiation bar height.
I think you're treading a dangerous road doing this kind of calculation, as you don't know what the future layouts for Android might be, or how they might differ on Google TV, or whatever.
Try calling getHeight() after onLayout. The view is not sized on inflate.
EDIT:
Or since Activity does not have onLayout you might wait for onSizeChanged.
(Reference How to know when activity is laid out?)
I am drawing image in native code and I need to pass the size of the screen to C.
I tried to get the Height by getHeight() of the view but that returns 0 always even after setContentView is called.
RelativeLayout masterLayout = new RelativeLayout(this);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT);
masterLayout.setLayoutParams(params);
setContentView(masterLayout);
when I try masterLayout.getHeight(), it returns 0.
I expected to get the full screen height as I said fill_parent.

Moving views inside a layout/view in Android

I have more than one question, but I'll start with the more important and problematic one:
I have a FrameLayout with a ImageView inside it. I need to get the size of the "usable area" of the screen my activity is ocupping, so I set the onSizeChanged on my View (I extended the ImageView class). Everything worked fine here. Now I have a 1000x1000 image that I want to show on the screen, but without scaling. I want it to be clipped, really. If I set the ImageView dimensions using viewObject.setLayoutParams(new Gallery.LayoutParams(1000, 1000)); I get the image being showed correctly, but then the onSizeChanged event returns me always the "1000 x 1000" custom size rather than the real screen size value.
Any ideas of how can I show an image with its real size (no scale!) and still get the view to report the screen available space? I can change the layout as needed as well, of course.
. Amplexos.
Are you asking to get the dimensions of the ImageView? If so then you can get that using getLocalVisibleRect. Here's roughly how it's done:
ImageView yourImageView;
public void onCreate(...){
setContentView(...)
yourImageView = (ImageView) findViewById(...);
(...)
}
getImageViewSize(){
Rect imageViewSize = new Rect();
yourImageView.getLocalVisibleRect(imageViewSize);
// imageViewSize now has all the values you need
Log.d("Your log tag", "ImageView width = " + (imageViewSize.right -
imageViewSize.left));
}
There is however a catch. You have to make sure that you don't try to get the size of the view until after view is finished being laid out on the screen. In other words, if you try to get its size in onCreate, its size will be 0. You have to get it afterwards, for example at the same time as you resize your image, assuming that's done with a button. (If you're using a SurfaceHolder you can also call it during the surfaceCreated callback, but I doubt you're using one of those...)

Categories

Resources