Android: while screen in landscape, recalculate the size of image - android

I am new to android and currently have project on hand. I did search some solution from Google and StackOverflow. I really have no clue how to do it.
In the project i did specify the size of holder image for display well during listview rendering image. Besides that i did calculate the size of item in listview in order to expand the listview in scrollView. But when it comes to landscape, i want the size that i specified to be recalculate, so the child of listview (such as textView) can expand. And the image I specified in portrait can expand (full screen) in landscape as well.
Please help! What steps i need to take for re-calculating it? or is there any other solution?
Below is the example of my layout, the size of image in landscape is same as in portrait ,i.e., as i specified it. So what are the functions that i can call once i change the view mode? Thanks.
___________________
|...................| ________________________________
|. .| | .................... |
|.Image Full Screen.| | . . |
|. .| | . Image could not . |
|...................| | . full screen . |
| | | .................... |
| Portrait mode | | |
| | | Land scape mode |
| | | |
| | |________________________________|
|___________________|

Related

Screen size and content dependant layouts

I would to inflate different layout for every screen size (different rows in list view), but for normal size I have to use two row layouts. Currently I'm checking the screen size, and if size is normal then I check once again which row inflate. Is there any better way to do this?
For example:
small
+---------+
| TITLE |
+---------+
| IMAGE |
+---------+
| CONTENT |
+---------+
normal 1
+---------+
| TITLE |
+---------+
| IMAGE |
+---------+
| CONTENT |
+---------+
or normal 2
+---------+--------+
| TITLE | IMAGE |
+---------+--------+
| CONTENT |
+---------+
You can use different layout file versions. For example, you're default layout is this:
+---------+
| TITLE |
+---------+
| IMAGE |
+---------+
| CONTENT |
+---------+
You'll save it in res/layout/my_layout.xml.
Then you want another layout for screens wider than 400dp:
+---------+--------+
| TITLE | IMAGE |
+---------+--------+
| CONTENT |
+---------+
You'll have to save it at res/layout-w400dp/my_layout.xml.
The file names must be the same, "w" means width (you can use "h" for height).
In your Java code, you propably don't have to change anything as long as you use the same ids for the same views in different layouts (e. g. R.id.title, R.id.image and R.id.content).

Looking for some Android layout advice

I have an issue where I need to add several (>20) to a layout at run time and the buttons can be 2 different widths and 2 different heights. I dont know the exact size of these buttons at design time as the minimum size will be determined by the device screen. So I thought I would use Linear Layout and use weights to manage the size of the buttons but you can only layout in one direction at a time, where I need the buttons to be able to double their size in either direction see below ascii art. I also looked at relative layout but I would need to specify the size of the buttons at design time which I don't as each user could have different layouts based on which buttons they want to emphasise.
<code>
+--------+
| | single size button
| |
+--------+
+--------+--------+
| | double width single height
| |
+--------+--------+
+--------+
| |
| | double height single width
+ +
| |
| |
+--------+
+--------+--------+
| |
| | double height double width
+ +
| |
| |
+--------+--------+
</code>
With that in mind this is a possible layout
<code>
+--------+ +--------+ +--------+--------+ +--------+
| | | | | | | |
| | | | | | | |
+--------+ +--------+ +--------+--------+ + +
+--------+ +--------+-+--------+ | |
| | | | | |
| | | | | |
+--------+ +-------------------+ +--------+
</code>
So I can't determine a way of building a layout that is this flexible and was wondering if you could tell me if building this layout can only be done in code rather than a more efficient and reusable xml based layout?
Regards
Damien
RecyclerView with StaggeredGridLayout from new Lollipop API. These classes are available in support library.
They let to make something like this,
it supports horizontal and vertical scroll, had be used like ListView and It can had be filled dynamically.
Or use any libraries, that you can find by key word - twowayview

VideoView not working for video with rotation on LG Android phones

With LG MS840, if I take a video in lanscape orientation, then display it in a VideoView, it looks same to what it used to be.
However if a take a video in portait orientation, then display it in VideoView, the video's width and height will be swapped and the image will be scaled to fit that swapped size.
For example, if an image in the video I took is:
-------
| A|
| |
| |
| |
|B C|
-------
The image in the recorded file still is:
------------
| A C |
| |
| B |
------------
Since when the video size is reported the rotation has been considered, what I saw is:
-------
|A C|
| |
| |
| |
| B|
-------
Any clue how this could be fixed?
VideoView does not support rotation of video even if composition matrix is set correctly and rotation attribute is used.
What you can do is to use TextureView and set its attribute rotation="90" (for example). It then will rotate the frames but the aspect ratio is something that you need to handle your self. In order to do so you can use textTureView.setScaleX((screenHeight * 1.0f) / screenWidth)
More details are here: Rotating an android VideoView

How to make the VideoView to be played in different layouts flawlessly when the orientation changes?

Say in portrait mode i made my screen divided into 2x1 matrix (2 VideoViews), so that two videos can be played simultaneously.
-------------------
| |
| |
| VV1 |
| |
-------------------
| |
| |
| VV2 |
| |
-------------------
Now, when i rotate the mobile to landscape, the screen will need to get divided into 2x2 matrix(4 VideoViews).
----------------------------------------------
| | |
| | |
| VV1 | VV2 |
| | |
----------------------------------------------
| | |
| | |
| VV3 | VV4 |
| | |
----------------------------------------------
So, in this case, when changing from portrait to landscape, i want below points needs to be achieved.
Neeeds to change the layout dynamically without any interruption in
the videos.(From 2 Videoview to 4 Videoview).
The Video should play flawlessly. Should not do pause and play
during orientation.
If you ppl advise me to use "configChanges="orientation"", how can i
handle the layout during orientation???
Thanks in advance
Using Fragments might be a solution. It does retain its state on orientation changes if you choose (so you won't lose instance objects), but also it recreates the layout, so you would be able to change current layout.

Combining SurfaceView with other Views such as TextView and Buttons

I'm totally new to android programming (just did some tutorials/read the dev guides etc.) and as every newbie I want to do a useless game :-).
Currently I'm struggling with the layout of different views. Similar to the example I've made a class which extends a SurfaceView and put that into a FrameLayout. Around this SurfaceView I want to have other View's like Buttons & TextViews.
Something like this:
-----------------------------------------------
| TextView | SurfaceView | TextView |
| | | |
------------ ------------
| | | TextView |
| | | |
| | ------------
| | | TextView |
| | | |
| | ------------
| | | |
| | | |
-----------------------------------------------
| Button Button |
-----------------------------------------------
I've managed to do something like this with a FrameLayout and RelativeLayouts (sticking the TextViews at the edges of the screen) but I'd like to better control the size of the SurfaceView as it should be a multiple in width and height of the object(s) I'll be drawing in it. I've tried setting layout_width and layout_height to some dp values but when I start painting at 0,0 it's still at the very top-left corner (where the TextView is..).
So, what's the best practice to achieve a layout as above? Using what layout? Or should I better draw my text inside the draw() function of my SurfaceView instead?
Layouts are the right way to combine OpengGL content with buttons, labels and other type of view objects. You can combine layouts inside other layouts... so you may build your screen step by step combining Linear Layouts or whatever you prefer.
For example, you can use a Relative layout to setup the buttons (b1, b2) and the rest of the screen:
+-----------+
| Zone 1 |
+-----+-----+
| b1 | b2 |
+-----+-----+
Then inside Zone 1, you can use a Horizontal Linear Layout for the 3 main columns
+----+----+----+
| c1 | c2 | c3 |
+----+----+----+
Inside of c2 you can place the SurfaceView, and in c1 the text label
Inside c3 will be a new Vertical Linear layout to display the text labels.
+----+
| t1 |
+----+
| t2 |
+----+
| t3 |
+----+

Categories

Resources