I have a webview and it displays a video link over the internet. Bu when the video was loaded it scales the view bigger than my linearlayout. But I want it fit into my linear layout. I've tried some methods like LayoutAlgorithm.SINGLE_COLUMN or writng the scale property manually but I couldn't find the right solution.
How can I scale it dynamically?
You may like to try setInitialScale ( http://developer.android.com/reference/android/webkit/WebView.html#setInitialScale(int) ). This will help to "zoom" the page (or the video) shown in the Webview to fit a particular width. Actually the size of HTML5 video in that page is decided by webkit engine and we cannot directly change its size from App layer.
You may also want to calculate the expected width yourself, due to the fact that Android devices have hundreds of screen resolutions and the width of your LinearLayout may vary on defferent devices.
Related
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 certain there is a way to make images(probably in SVG format) fully responsive to different screen sizes in an android application, but how is that achieved?
I've tried increasing the width and the height of an ImageView to, let's say, 400dp but it is still static and won't look as big on a tablet.
I am currently trying to make it work with a ConstraintLayout constraints but I can't quite figure it out. It stays centered, but I can't make it bigger.
Please point me in the right direction.
I have a JPEG photo which I want to use to as a background for one of the screens.
I want the behaviour to be simlar to the css backgroundSize: cover property. (Play with the following tool to see what I mean: https://davidwalsh.name/demo/background-size.html)
For iPhone, this issue is fairly easy, as you can literally have several different versions of the same image depending which iPhone the app is being installed on.
For Android, this is much more difficult as they have various different aspect ratios and resolutions.
Therefore my question is, how can I specify an image that covers the entire screen.
You can always fake this by adding the imageview inside a View and calculate the proper height/width you need to cover the screen (get the shortest side and scale it up and multiply the other side by the original ratio).
You could also use https://github.com/AndreaVitale/imageview that supports a cover mode
For Android, My suggestion is to use 9-patch Image instead of normal image. It will stretch it self to entire Screen, if you placed image as background
of Window it self as well as worked for ImageView perfectly.
Thank you.
I want to create my button height using drawable xml file and it should also resize dynamically with my layout, so that it can support any Android device.
Currently I am using RelativeLayout with match_parent height. I want to put a set of 3X4 buttons in this layout and should automatically resize with the device height.
I am not able to resize it properly when I use dp values. If I resize the button for large res device, it is not working fine for 240X320 res device.
Yes, you should be able to do what you want with the Android layout classes. You aren't completely clear, but it sounds like GridLayout is what you want.
The default Android UI element should deal well with being sized dynamically; if you have a custom drawable asset, you'll want to make an appropriate 9-patch image at each of the common display densities (so that it not only resizes correctly, but looks good on a range of devices).
I have recently been thinking about this very topic, and I think I can help you. If I understand you correctly, you would like to have your application dynamically resize your buttons depending on the screen size. In order to do that you can use binding and a converter. If you bind your button's height (and width if you prefer) to the page's height (and width) you can use a converter to convert the value to a percentage of the screen size. If you like, I can provide you with some sample code.
You can get the size of the display Display display = getWindowManager().getDefaultDisplay(); and set the sizes dinamically.
Or, you can make various sizes of your images.
I have an Android Gallery setup on a layout with both the width and height set to Fill_Parent. This works great for smaller screens, but as the display size grows into the tablet sizes, the Gallery stretches to a layout that is taller than it is wide. At this point, there are no more side images on it - that is, just the main selected image is visible. I want to have at least a small amount of the side images visible so the user knows the view is scrollable.
Does anybody know how I can do this?
Is it possible to maintain an aspect ratio while still using fill_parent? Is it possible to set the Gallery view to show a certain amount of the side images? etc?
Thanks!
The Gallery class is pretty limited and personally I tend not to use it. Have you considered using a ViewPager instead?
AFAIK, If you are using
android.widget.Gallery
then the implement a custom adapter to the view, and set a layout wrapped to each items inside the gallery view. If you still don't understand what I just said, I would try to generate some reference code.