TextView height according to the screen size - java

I need to place TextView at the Top of the screen.
In different situations its height is different.
I want to make TextView scrollable if it spaces more than 40% of the screen.
Of course if it has 3 words only it must space only a row.
Any idea?

You can use SDP - a scalable size unit
An android SDK that provides a new size unit - sdp (scalable dp). This size unit scales with the screen size. It can help Android developers with supporting multiple screens.
For Texts Use SSP - a scalable size unit for texts
An android SDK that provides a new size unit - ssp (scalable sp). This size unit scales with the screen size based on the sp size unit (for texts). It can help Android developers with supporting multiple screens.
Try any of these. I think these will help you alot

Give android:layout_weight="1" in xml
and use textSize in sp not dp

Use dimen file for setting text size & give padding

Related

How Can I change according to the size of the device

I want change according to the size of the device so I want make responsive app . How Can I? How Can I support multiple device size?
How it looks on Nexus S 4.7":
How it looks on Pixel:
Use dp whenever specifying sizes other than TextSizes
Use sp while specifying text sizes
Use RelativeLayout in your xml so it will adjust according to the screen sizes
Use SP whenever you want to make text user dependent
That means if user has set large text size in his/her device then all texts in all app's whos dimensions are in sp automatically change in large text. Therefore it is recommended to you sp in text size
Whereas dp is fix and no user settings are apply on dp therefore it is recommended to you dp dimensions with elements you to fix like margins and paddings
For your problem providing 'dp' should work perfectly but if it is not working they you might have some other problem therefore try to provide more details about your project
For more details read this:-
https://developer.android.com/training/multiscreen/screendensities
Use ConstraintLayout
Use match_parent and wrap_content instead of fixed values for views.
Use dp and sp instead of fixed units for the size of the views and the size of the text respectively.
Create multiple layouts according to the different sizes of the screens.
You can get more details about it on the official documentation.
By the way, to create multiple layouts for a particular layout, go to the design tab of the layout. Click on the Orientation for Preview icon in the toolbar. From the drop-down list that has appeared, select Create Other.... Now a dialog might have appeared. Do not change anything except on the left side of the dialog, there will be an Available qualifiers section. Select Smallest screen width or Smallest width (according to the options available). Click the >> symbol and enter the minimum width of the screen you want to design the layout for. For example, you enter "600dp", then the layout created will be for devices with 600 or more width (dp) as their screen width. Click Ok and a new layout will be created for a different set of screen sizes.

Exactly same size for all screens physically in Android

how is it possible that dimensions of any object physically same size on all screens?
From the android developer's documentation:
To preserve the visible size of your UI on screens with different
densities, you must design your UI using density-independent pixels
(dp) as your unit of measurement. One dp is a virtual pixel unit
that's roughly equal to one pixel on a medium-density screen (160dpi;
the "baseline" density). Android translates this value to the
appropriate number of real pixels for each other density.
For example, consider the two devices in figure 1. If you were to
define a view to be "100px" wide, it will appear much larger on the
device on the left. So you must instead use "100dp" to ensure it
appears the same size on both screens.
So, what you are trying to achieve is possible using dp as the unit for the height and width properties of the object.

i need font sizes in app not to get effected by changing Settings Font size

I have my app running well as per design when the font size is at "Normal" on Settings->Display->FontSize.
When i change the font size to Small/Large entire content is mashed up. My app is content intensive and this is badly effecting the app.
From the Android developer training on supporting different screen densities:
The sp unit is the same size as dp, by default, but it resizes based on the user's preferred text size.
In other words, when the user's font preference is "Normal", dp and sp units are identical. It is only when the user changes the font preference that the sp units start to scale up or down.
That means that if everything looks good in your app now when the font preference is "Normal", you can just change all of your sp units to dp units. This will cause no change to your app when the font preference is "Normal", and will additionally make sure that nothing changes when the font preference is anything else.
Despite this is not encouraged, you can use dp instead of sp for your text size specifications.
use dp instead of sp, here is why:
android devices have multiple screen sizes and the same device can rotate screen; for you your app to look the same on multiple devices the responsive design concept came to existence, which mean widget and text size should adapt to the new screen parameters. So dp is not responsive and will look the same no matter what the screen size is, while sp is somewhat more responsive and takes into the account user preferences settings for accessibility sake.

Android. Too small text in TextView

I follow the Android guideline and set text dimensions in "sp" units. In one of my layouts used for a ListView row all TextView sizes set to 8sp or 12sp. I tested the app in emulator with all possible screen dimensions and things went well. But some users (with Galaxy Ace and ZTE Blade) say that text in that ListView is too small (a couple of pixels per char).
Why does it happen?
read this post What is the difference between "px", "dp", "dip" and "sp" on Android?
personally use "dp" unit; is more consistent
Basically you're letting the user select the font size when using SP. This is not a bad thing per sé, but it can lead to unexpected results when devices reports small sizes to the API (either because of user actually selecting a small text size, or a bug in the device software).
If possible, try increasing the units font size to find out what font size the user is using on his device. My guess is that it is set to be very small. If you don't have access to the devices I would stick with using DP.

Android: Scale fixed Layout down

i want to scale my android application, basically i developed it for 800x480 display with a AbsoluteLayout. This is necessary for my Application, i can't change it.
Now the Problem:
When i start my app in the Emulator the buttons disappear and the images are extremly large. I thought android would scale applications with a fixed size down by default, but it does not work. I already tried to manipulate the manifest but this did not work.
I use a ImageView component for graphics.
Targeting Android 2.1
Cheers
Felix
It is definitely not ideal to use AbsoluteLayout. But, if you want to just push through with it, you should switch the units of all your co-ordinates and sizes away from px (pixels) to dp (density independent pixels). You will have to scale all of your existing co-ordinates by a factor of 2/3 to start, since 1 dp = 1.5px at the density that your layout targets (hdpi).
You will need to explicitly specify the sizes of all your images and layouts. If, for example, you had a button that was 30px wide and 120px tall, then it will become 20dp wide and 80dp tall.
Of course, the images won't look great on smaller (mdpi) screens, since they will be scaled to 2/3 size. Also, some devices are fixed to landscape mode, where you will definitely encounter layout problems. So it's not pretty, but it may get you over the finish line, depending on your requirements.

Categories

Resources