TextView dp does not scale with screen size - java

I am attempting to create a textView that will take up a large portion of the top center part of the screen. Ideally, setting the text size in dp would allow the textView to remain the correct relative size (taking up about 70% of the width of the screen, and maybe 20% of the top). It looks correct in the layout editor, and in the emulator at HVGA resolution. However, when I test it at higher resolutions (on my tablet, or emulating a 720p display) the text takes up a very small portion of the top center part of the screen. (maybe 30% width instead of 70%, and it doesn't seem any larger vertically).
Is there a way to scale text to correctly increase relative size with resolution?

Set the layout_width as fill_parent, which will make it spread across the screen for all devices.
Add some padding on left right and top which seems suitable.
The padding might seem different for different screens but still this might be a better solution.

set
android:layout_width="match_parent"
edit:
check this out
Auto Scale TextView Text to Fit within Bounds

Related

LIBGDX drawables on devices with different densities/resolutions

I'm new to LIBGDX game development, and I have faced my first problem. I've created 9.patch drawables (buttons) using texture packer. This drawables can be used on low density and also extra high density screens and quality is the same.
If I run my project with that drawable on desktop project the image shown is okay and perfect size. If I run project on low density android device, drawable becomes huge (almost half of the screen). And also If I run project on extra high density android device the button becomes really small.
So my question is, how to handle drawables in LIBGDX, so the ratio (screen:image size), stays the same no matter resolution/density..?
If your button is a text button. Change the font of your text.
If you are using image button, this might help you
It kind of depends on what you're drawing...If you are just drawing an image, I've found it easier to specify a float width and height in the last 2 parameters of the draw method. If you are using a camera with a fixed viewport size, you can simply use a fixed percentage of your camera viewport so it will always be the same dimensions and draw like this:
batch.draw(drawable,x,y,screenwidth * 0.5f,screenheight*0.5f);
However, if you are using buttons or some other widget inside of a table, you should specify the cell size and it should automatically be resized based on the size of the table cell. Something like:
myTable.add(myWidget).width(300).height(200);
Post up exactly what it is that you need to draw if you get a chance and it will be easier to figure out what needs to happen.

Android - Text View Change Font Size quickly

I have an activity layout that have only one text view filling the whole screen. I want to display a matrix of characters in that text view. Assume the dimensions of such matrix are not lower than 800 x 600. I have made the text view scrollable, so that the user can move around both horizontally and vertically. I want to be able to reduce the font-size of the text, let's say every time the user tap the screen, so that if you touch it several times you will end seeing nothing but a little black square since the characters will be no longer visible due to their size.
The problem is that the text view is too slow updating the new font size every time a tap occurs. I want to create the illusion of a zooming out if you tap quickly. Is there any way to accomplish this faster?
I would suggest to load data on webview if possible and u can easily zoom in and out in webview and loading data would also be simple

Vaadin relative sizing with component proportions?

I have a GridLayout I'm making which is populated with a bunch of pictures. The GridLayout itself is set to SizeFull(), as is each individual image in the grid.
The grid with the pictures is within another grid, and that grid has relative sizes set.
With this set up, the grid of pictures stays within the spot I want it to, properly resizing to fit within the space they should, but the pictures do not retain their proper square proportions. They squish fat or skinny however they want. I want them to retain the original proportions, though, so they expand to fill their available area as much as possible while retaining those proportions.
If I set the width to 100%, or the height to 100%, and leave the other undefined, then it retains the proportions, and properly expands to fit the one that is set to 100%, but the other spills outside the nested grid layout's spot in the upper grid layout.
Anyone know how to do this?
Have you tried setting the width and height as percentage?
So on an image of 80 by 120 pixels:
setWidth(66, Unit.PERCENTAGE)
setHeight(100, Unit.PERCENTAGE)

Multiple drawables background images to fit the screen resolutions

Alright, so I have an image that it's resolution is: 1054X1054.
I want to set that image so it fits exactly the screen size of the android devices. (I'll cut the image in some editor as nessacary).
So my question is: How can I know what resolution my image should be so it will cover the device background without needing to resize the image.(For the mdpi,hdpi,ldpi)
I'm asking that question because I keep missunderstanding how the "multiple screen resolutions" really work..
you can design your image to re-size with different screen sizes, you'll discover that each design requires a minimum amount of space. So, each generalized screen size above has an associated minimum resolution that's defined by the system.
android os count sizes in "dp" units—the same units you should use when defining your layouts—which allows the system to avoid worrying about changes in screen density.
xlarge screens image sizes are at least 960dp x 720dp
large screens image sizes are at least 640dp x 480dp
normal screens image sizes are at least 470dp x 320dp
small screens image sizes are at least 426dp x 320dp

Positioning images to fit all size screens

I'm having a problem with positioning images,I need to position a lot images over another larger background image.
An image Like this
I have tried Absolute but it does not keep the position of the image say I wanted to put a clip art image of a board pin over the background image and need it pointing at a sun and when it's clicked I get a popup dialog,
but then when I change the size of the emulator screen the clip art image is not at the same position I wanted it on the background image.
I first tried just putting the clip art on it with a image editor and used onTouch Listener but that didn't work out when I changed the size of the screen with the x and y coordinates. And tried Absolute Layout and that doesn seem to keep the position.
any ideas would help me big time thanks
AbsoluteLayout is deprecated, so it's probably best to use relative layout alongside with dp.
You could use relative layout so you can use layout_below="#id/view1", android:layout_toRightOf="#id/view2", and android:layout_toLeftOf="#id/view3". You can also use android:layout_marginLeft="10dip", android:layout_marginRight="10dip", android:layout_marginTop="10dip", and android:layout_marginBottom="10dip" to move the views left/right and up/down relative to their current positions. There is also ALIGN_PARENT_LEFT, ALIGN_PARENT_RIGHT, ALIGN_PARENT_TOP, and ALIGN_PARENT_BOTTOM. Click here for more properties.
You can manually calculate visible width and height of the image by using its drawable's getIntrinsicHeight() and getIntrinsicWidth() and then set Image's scaleType to FIT_XY (this saves image's ratio, and also makes its size correct, while FIT_CENTER does not).

Categories