autofit 2-textview size in android - android

I have a relative layout and in that i have 2 TextView. I want to adjust the size of both textview as per the user screen size, means if the user has screen small then both, textview will adjust there textsize into half of the screensize so that they both could fully fill screen by width.
Like this:
there are 2 Textview in images getting adjust as per screensize to fit the width.

Related

Maintain the same view size on different screen orientation

I have created a layout that consists of imageviews and textviews. When I run the App every thing is fine on portrait screen orientation, but when I rotate the device to be in lanscape the imageviews shrinks (smaller in size).
I want to have (regardless of the screen orientation) the same size of views. I do not want the views to look smaller or bigger, I want the same sizes across different screen orientations.
Note: All dimesnions in the layout are in dp for width and height and the text font it is in sp.
Are your ImageView's being sized by attributes that align to edges, and then margin distances? This would distort your image as the parent boundaries change on device orientation.
Also, please provide your xml code, I don't have the reputation to ask as a comment.
Android tries to help you create responsive layouts (layouts that change the position and size of elements depending on how large the device screen is) through the use of things like layout_weights, settinging the width/height to match_parent, etc. Because of this, if you use these attributes and then rotate the phone screen, the size of your images is going to change because the system will think that you want to text/images to change size depending on orientation or device screen size.
Even if you mix layout weights and hard coded dp pixel sizes this will happen - what happens is that android measures all of your hard coded values and wrap content values, and then for any extra room on the screen, it expands the views that have weight, proportional to the weight number you give them. This is why you'll sometimes see people setting layout_height="0dp" and then setting a weight.
If you want an image that is always the same size, you can hard-code a certain number of dp pixels and remove any mention of layout_weight or match_parent. You can hard-code margins too. Depending on the size of the image, this will mean if you view the image on a phone that's too small, part off it will end up off-screen. There are a variety of ways to deal with this depending on what you want to happen. For example, if you want to elements on the screen to stay the same size but rearrange themselves depending on the device's screen size, you can make multiple layouts for different screen sizes and use resource folder qualifiers.

Show 2 square pictures above eachother, taking 50% of the width of the screen

I am a webdeveloper, and I am very lost in all the Android screen settings for aligning content. I've seen weight, gravity, scaletypes of the image etc. etc.)
I hope I can make my intentions clear, and that it's possible to fullfill them.
In this picture of a phone screen, I have 2 square pictures (the purple and the green one).
What I want to accomplish is that the width of the pictures always take up 50% of the screen width, and that it is centered (so the margin left and margin right is 25%).
So let's say you have a 600*800 screen, the width should be 300 pixels and the margin left and right would be 150 pixels (or better 25%). On a 768*1024 screen the width should be 384 pixels.
The height should follow that size (I've tried a lot of code, and the best result was that the width was sort of a pertentage, with 3 relative layouts in a lineair layout, but then only the width was correct, but the height wasn't)
Depending on your screen size it could be that the height of the two images together would be higher than the screen and a scrollbar would be neccessary)
Wrap them in PercentRelativeLayout and fix their width 50%. set their height equal to their width in Java when the view gets populated

Textview Fit to Screen Width in android for any device

I have TextView which contain text "3D Android Graphics". I want to stretch the text so that it should always fit to screen width of any device provided. Means its text size should be changed according screen size and it should always occupied entire screen width. What should i use to get it done?

button position multi screen

My problem is very simple.
I have a button that have 100dp marginRight and 100dp marginTop in a xxhdpi density screen.
The problem is, when I change to another density screen or size, the button its not in position I want. It remains the 100dp margin top and right but I don’t won’t this.
I thought that if I use dp, when I change screen it’s was going to be in the position I want, calculate de position in smaller or bigger screens.
I hope you understand, I don’t want to create a layout for every density or size screen.
How can position a button that be in the same position in every screen?
on a different screen density that 100dp will change position.
what you can do is support multiple size and create different layout for each.
read http://developer.android.com/guide/practices/screens_support.html.
Using the new size qualifiers is a solution.

Height and Width params relative to the device's screen height and Width

I have a requirement that the layouts and views into an activity is Dynamically added. The layout creating programmatically. The width and height of all layouts and Views are need to be relative to the screen width and height. For example if the height of a Layout to be added is say 50%, then the 50% of screen height ( 50% 1280 in Pixel, in case of Nexus 4) should set as the height of layout. I have an outer scroll view also to view the Views added beyond the screen.
My problem is if I created a layout with 100% screen height and width, then programmatically I am setting the height of layout as 1280 pixels, and width 768 pixels (e.g. Nexus 4,768*1280), logically the added layout should fit the device's screen. No scroll should enable. But in my case scroll view is coming. When I hardcoded the value for a layout width = 768 and height = 1280, it starts scrolling. How can I achieve the height and width to the views relative to the device's screen.
I am getting the real height and real width of device from here link

Categories

Resources