Category: How to set height and width of videoview in android

How to set height and width of videoview in android

Like in HTML. Android Layout height equals 50 percents of parrent. Your email address will not be published. Notify me of followup comments via e-mail. This site uses Akismet to reduce spam. Learn how your comment data is processed. Here I want to talk about mock responses for your Retrofit.

Sometimes we should continue mobile development even backend not ready. We can be never blocked on it if will use mock responses. Sure we Read moreā€¦. Below you can find code which help you find if SIM card available in the device. There two solutions. Here is few lines how to get size of directory in Android. To get size of directory you need sum sizes of all files in this directory and subdirectories.

So, we need recursion. Categories: Android Development. Leave a Reply Cancel reply. What's on your mind? Related Posts. Android Development How to create mock server response and connect to Android Retrofit Here I want to talk about mock responses for your Retrofit.

Android Tutorial How to Set Height and Width in Percentage of a Button with ConstraintLayout

Android Development Detect sim card availability in the Android dual sim device Below you can find code which help you find if SIM card available in the device. Android Development How to get size of the app data in Android Here is few lines how to get size of directory in Android.By using our site, you acknowledge that you have read and understand our Cookie PolicyPrivacy Policyand our Terms of Service.

The dark mode beta is finally here. Change your preferences any time. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. The VideoView documentation states:. Displays a video file. The problem is the Samsung Galaxy S3 is doing weird things to the video and not respecting the ratio of the video.

What I have found is when the video is played on the Samsung Galaxy S3 it will play in an incorrect ratio. It looks like it has been stretched to the height of the view without any regard for the ratio of the original video. If I force the video to take up the full size of the fragment it looks ok on the S3 because the ratio of the screen is the ratio of the video.

However I don't want to do this as it screws up the fragment being used in other places i. An Activity with a Fragment with a VideoView. When the system asks the video for it's width x height it is returning x when it should be returning x Either way I have circumvented it by adding what I know the video's width and height is to my code. I have updated the Git Repo with this fix. Here's a link to the question where I found out the different size details of my video.

Here's the VideoView answer:. Learn more. Asked 7 years, 2 months ago. Active 7 years, 2 months ago.

how to set height and width of videoview in android

Viewed 7k times. Activity with full screen fragment: What I have found is when the video is played on the Samsung Galaxy S3 it will play in an incorrect ratio. Blundell Blundell CommonsWare I haven't, you think there is that much difference?

how to set height and width of videoview in android

I'll give it a go. Means I have to look after the state more myself.

how to set height and width of videoview in android

Somewhere, manufacturers have tinkered. The one spot they could have tinkered that is relatively easy for you to recover from is if they tinkered with VideoView. You could even just grab the VideoView source code, drop it in your project refactored into your packageswitch to using your copy, and see what happens. If the problem is fixed, then stick with your private VideoView.

If the problem persists, then the issue is deeper in the media playback stuff a. CommonsWare Yeah true. However MediaPlayer System. Wow, VideoView got a lot more complicated than the last time I looked at it. Sorry to steer you in the wrong direction on that front.

Active Oldest Votes. This is not a bug I think as I have this problem with a specific video that has width and height of x and x too in it's Metadata. I will post an separate answer soon.By using our site, you acknowledge that you have read and understand our Cookie PolicyPrivacy Policyand our Terms of Service.

Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. I have created a custom view named Graphview. Here is the structure for the GraphView class. I have added the view in a tablerow using addview. It is working fine. Now I want to set height and width for the GraphView.

How to do that?

How to set View width (height) in percentage of parent View in Android

This is fine if you know the exact size of the view. You can find an example on how to override onMeasure by looking at the android docs and the LabelView sample in your SDK directory. This is a Kotlin based version, assuming that the parent view is an instance of LinearLayout.

This allows to set the width and height and in a single line. How are we doing? Please help us improve Stack Overflow. Take our short survey. Learn more. Android set height and width of Custom view programmatically Ask Question. Asked 9 years, 1 month ago. Active 5 months ago. Viewed k times. Akram 7, 7 7 gold badges 42 42 silver badges 70 70 bronze badges. Active Oldest Votes. The easy way is to set the size programatically like that : graphView. Dalmas Dalmas Would be helpful to know which LayoutParams you are importing there.

The LayoutParams should be from the layout where the graphView is placed. You can set height and width like this: myGraphView. Eric Nordvik Eric Nordvik You should make sure the LayoutParam class you use is from the correct parent Layout class. LayoutParams class. This also does work and ensures you use the correct LayoutParams class: simply do myGraphView.

If you do this. I think it's odd that this answer is getting more points. Be careful about using this. Thanks yincrash for pointing that out. Rakshi Rakshi 6, 3 3 gold badges 22 22 silver badges 46 46 bronze badges. It gets reflected automatically. This is the advantage of object oriented approach. So params. You should refer the view for which you have to set the height.GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community. Already on GitHub?

Sign in to your account. Right now in sample project FrameLayout height is dp. Can you add this in your library itself or please let me know how can I do my self! If you dont know the size and wanna use the video size, then u may need to wait for OnPreparedListener callback to get the video size.

So do something like the following in onPrepared. However, I believe this is not good practice as an item of recyclerview since u need to wait some time to get the size of video. This causes non-smooth scroll. Skip to content. Dismiss Join GitHub today GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together. Sign up. New issue. Jump to bottom. Copy link Quote reply. This comment has been minimized. Sign in to view.

Still, thank you for some solution. Sign up for free to join this conversation on GitHub. Already have an account?I am using android gridview in Xmarine c project. Orientation; if LayoutOrientation! LinLay ; Lin. GridMiddle ; GVMiddle. NightFury said: I have tried you scenario then i got following exception.

GridMiddle. Xamarin Inc. This site uses cookies for analytics, personalized content and ads. By continuing to browse this site, you agree to this use.

Android VideoView

Learn more. Xamarin Menu About What is Xamarin? What is Xamarin. August edited August in Xamarin. How to do this? Tagged: android layout android design xmarine Xamarin Android Activity. Best Answers. August edited August Accepted Answer. Lets give try for it and let me know its working or not.

August Accepted Answer. NightFury said: I have tried you scenario then i got following exception android app actionbar layoutparams cannot be cast to android widget linearlayout layoutparams as per my opinion your trying to modify LayoutParams of child view which is your GridView which have parent layout like Linear or Relative or Something else.

August edited August ClassCastException: then app crashed. August GridMiddle ; still the same error is coming. I am using C application.

Happy coding.Android VideoView class is used to display Video files in them. Following are the acceptable formats:. VideoViews can play videos either from resource files, local data or url specified.

Following are some of the methods used on VideoView:. For having media control inside the video, we need to set the onPreparedListener on our VideoView and then set the anchor inside it. This way the MediaController is set inside the VideoView. It should be done to prevent memory leaks. Now the output of the above application in action is given below:. This brings an end to android video view tutorial.

You can download the final Android VideoView project from the link below. Thanks for example. This video player is not showing volume controller. Can you explain how to add that. Your email address will not be published. I would love to connect with you personally. Table of Contents 1 Android VideoView 1. Android Studio VideoView Project.

Shoot him queries. Follow Author. Comments Manish says:. February 6, at pm. Leave a Reply Cancel reply Your email address will not be published. Leave this field empty. Newsletter for You Don't miss out! Subscribe To Newsletter. We promise not to spam you. Unsubscribe at any time.

how to set height and width of videoview in android

Generic selectors. Exact matches only. Search in title. Search in content. Search in excerpt. Search in posts. Search in pages. I am a Software Developer just like you and hate spamming.By using our site, you acknowledge that you have read and understand our Cookie PolicyPrivacy Policyand our Terms of Service.

Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. But the VideoView matches the width of the parent container, and then the height is set according to the aspect ratio of the loaded movie.

I would like to do just the opposite, I want the VideoView to match the height of the parent while keeping the aspect ratio intact, the video will be clipped on the sides. This works great, and the controllers always stay on, but the height of the controllers is not being taken into account when calculating where to place the video since it's vertically centered. Call setVideoSize before video view is shown, you can get video size from thumbnail extracted from video.

If you want to account the height of controllers, you can do it yourself in the onMeasure method. I solved this problem with layout. It seems that it worked fine when it was pinned to the corners but it caused the video to skew. To test I changed my relative layout's background to to see the red poking through. Regarding question 1, I am surprised no one has mentioned the possible use of the MediaPlayer's scaling mode. It has 2 modes. Both of them always fill the view area.

That solves one part of the problem. The other part is to change VideoView's measuring behavior, just as some of the other answers demonstrate. This is the way I did it, mostly out of laziness and not familiar with the metadata API's that the others use, you are welcome to use this method or one of the other methods to fix the size of the view.

The blanket catch ensures safety when this is called before mMediaPlayer exists, as it may be called many times, and also falls back to old behavior should the field name ever change.

So using this class in the layout, you just change the scaling mode on the media Player wherever you have a chance. Such as:. No need to create a custom view extending from VideoView. This will set the widthSpecMode of the video view to View. For the first time a question answered my issue instead of answers!!

My issue was that I had a white space under the video on full screen. That, and having the VideoView centered vertically in its parent. I wrote this as a comment but then thought someone might have the same issue I had, so here it is as an answer also.

First create a VideoView in a RelativeLayout like this:. Of course this only works with aspect ratio's but you could just use your aspect ratio to change either the height or the width. I have been looking for ways to display video in aspect fill in VideoView but after trying many solutions, none of them seems to work. How are we doing? Please help us improve Stack Overflow. Take our short survey. Learn more. VideoView to match parent height and keep aspect ratio Ask Question.


thoughts on “How to set height and width of videoview in android

Leave a Reply

Your email address will not be published. Required fields are marked *