Making activity_main-small is not working properly - android

I read that to support different screen sizes you have to make a new layout (with the same name) for the different screen sizes (small, large, xlarge, normal).
Im trying to start with the small one but for some reason whenever I create it, the preview gives me Wear Square screen (a squared screen) and I can't change it to a small screen (as shown in the picture)
What can be done for this to support a small screen sizes and a large ones?

Possibly you even do not have such small device to see your layout in action.
The one you select on screenshots is watches - they should apply another suffixes.
Like a alternative way - try to use percentage attributes in ContraintLayout and autoSize attributes for TextView.

Related

application not fit to the android virtual device

In my android application, I have a problem that when I run my application, its not fit to the emulator and some part cut on it like below:
And also you can see below I have a button also on it like below image:
But its not show me the full image, means a button is missing on the emulator.
How can I resolve it. kindly suggest me, waiting for reply.
Thanks
Basically, your designer and emulator are using different screen dimensions.
You can change the designer to use the same screen dimensions. Currently, from your screen shot you're using the Nexus One layout. From what I can tell the emulator doesn't look like the Nexus One screen dimensions.
With Android it isn't as simple as 1 layout for all dimensions, screen sizes and devices. You have to implement multi-screen support to address this. You can usually do this by having a variance on dimensions, styles and layouts. A lot of the time one layout will work universally, but dimensions often need tweaking.
See http://developer.android.com/guide/practices/screens_support.html for more on Supporting Multiple Screens.
It is a problem that can occur in real devices (remember, we have loads and loads of different screen sizes for android) so you definitely need to fix it.
The best way to avoid this is to wrap the entire layout inside a ScrollView, so the user can scroll to see all the content of your layout.
If you are trying to fit all the elements on the screen then you need to account for different screen sizes and densities. In your particular case you are building the screen on a different sized screen than the emulator.
Assuming you do not want the screen to scroll (which is solved using a ScrollView), then to fix this, you can do the following:
Build different XML layouts for different screen sizes
Use dimen files to specify different sizes for some or all elements on the screen so that they re-size depending on the screen size.
Use weighted LinearLayout so that Android re-sizes the elements according to the screen they are placed on.
Each of these is pretty easy to search and find various ways of doing.

Support multiple screen sizes in Android with just one layout

I read something about supporting multiple screen sizes in Android.
For that most of the answers recommended to create different layouts
(layout-normal, layout-small, and so on). But that would mean that
I have to define all my layouts multiple times. I don't think that
this is a smart solution.
Is there no way to create just one layout and to automatically scale
it for any display size?
There are several parameters in layouts in android that adapt themselves to the size of the screen (fill_parent, center...), however I have not seen in android's layout parameters for everything... for example 1/3 of width.
Finally what I am doing is the following:
One layout per architecture of the interface. For example, in tablets I change the architecture, integrating sometimes 2 layouts in one.
Include, programmatically, changes of sizes. For example, an button I want to be 1/3 of the screen I need to programmatically obtain the width of the screen and change the button size.
Always include several sizes of icons that android automatically selects depending on resolution.
But there is a significant part of the job that needs to be done "by hand".

Make View grow with screen size

I have a FrameLayout that is used to display a camera feed for scanning with ZBar.
I would like it to take up a large proportion of every screen the app runs on. A hardcoded 275dp square looks great on the latest phones but pushed stuff off when for smaller screens.
I am planning on hardcoding a 175dp square and then in code making it grow based on the dimensions of the phones screen.
I'll probably do a switch on various screen sizes and then decide what to resize the frame to.
Is this a good approach?
How would I go about doing this in XML?
A LinearLayout with layout_weight specified for height/width will allow you to simulate a percentage based layout, otherwise you can use fill_parent when you want to use the whole screen width/height.
You can make one xml layout file for ldpi, mdpi and hdpi(xhdpi and tvdpi if you want to) and literally set different xmls according to the screensize. With this you will be able to fit most screens without a problem, but it is not as accurate as percentage. But remember that not all android devices has the usual 16:9 or 16:10(8:5) and therefore percentage may make the square a bit different from screen to screen.
You can make your own layout qualifyers, but the standard ones are in most cases more then enough.
You should also consider makeing only the frame layout in java, and the rest of the layout in xml.

Android one PNG screen image with EditTexts located on screen

I have a full screen png image with all descriptive text for each EditText. I want to place the six EditText input areas at the correct positions on the screen.
I understand the different layout folder names for different screen sizes, densities and orientations. So I would have different layout XML files for each.
My problem is how to place the EditTexts at the correct location, and have them scale what would be small amounts with the small variations of sizes as the full screen png image will scale.
I believe that I should not specify locations, even with density independent pixel (dp |dip), as they may not work in future versions.
I cannot find anything on searching for this problem. What I can think of is a Relative Layout with blank or transparent dummy TextViews pushing the EditTexts to the correct positions.
My reasons for doing it this way with one png image for all the non-EditText parts of the screen are (I think)
- Can get a nicer screen image
- Is more efficient to place one png ImageView on the screen
- Is how it was done in another mobile environment
Any thoughts or suggestions?
My recommendation is that you remove any text parts and other that needs to be aligned from the background image, then create a RelativeLayout where you can add these as real TextViews/EditTexts.
This will give you the best result and flexibility considering all the different screen sizes and resolutions available for Android phones and tablets.

Android, Which screen size do you develop for?

I am creating a simple game in android so I can create something and learn how to program in Android (I'm a noob).
Right now in my layout editor (i think thats what its called, basically the place where you can create your layout xml files) there are many sizes on the top left... which one should i target? do i need to make a separate layout for each one of them?
Thanks!
R
The screen size selection is only intended to give you an impression of what the layout looks like on various screen sizes and densities. A good place to get started is Common Layout Objects and Supporting Multiple Screens.
When developing for Android, you should not target a specific screen size, but instead make layout elements fit proportionally. An exception may be x-large displays such as tablets, for which a great read is Distributing to Specific Screens. An example of getting elements to position nicely is this question.

Categories

Resources