I have created an extremely simple example of my problem. In this app there are two buttons (neither of them do anything just supposed to be there and be able to be clicked). In the .xml file I have the Pixel phone selected and have laid out the buttons to fit the screen correctly (using match_parent for width) (.xml file). But when I run the application on my Pixel emulator (not edited at all) only second button shows up and the width isn't right (Emulator). This feels like it has to be operator error considering the extreme differences. Any ideas?
Related
I've been searching docmentation and forums, and from all I've read so far, I conclude that in order to support portrait and landscapce modes, I need to code two identically named layout XML files, one in res/layout, the other in res/layout-land. Each layout places the widgets corresponding to the mode.
But what if there is no corresponding layout in res/layout-land (or if the later doesn't even exist)?
From a simple app containing a single text view in a ConstriantLayout, I see that the layout correctly adapts to the device orientation when run on my physical phone.
However, when run on a virtual device (Pixel 4 XL API 28, if that matters), the view is not changed when I click on the Rotate left or Rotate right buttons.
But, after clicking on the rotate button, a rotate icon appears at the bottom right of the virtual device. Clicking on that rotates the view.
Basically, my questions are:
Why is the layout correctly rotated on my physical device despite the fact that no landscape layout is present?
Why does the virtual device not rotate the layout when clicking on the rotate buttons, but offers me a rotation by displaying a temporary rotate icon?
A pointer to some documentaiton where all this is described in detail would be nice. It sure must be documented; I just haven't been able to find it.
Devices have a setting to enable or disable auto-rotation - on newer devices, when this is off, that rotate button appears which allows the user to choose to rotate (i.e., manually rotate).
As per the providing alternative resources, the most specific matching resource is used. So if you had a layout in layout-land, it will take precedence over that same resource in layout. (but wouldn't apply at all if you where in portrait mode as -land would disqualify that alternative resource).
That means that alternative resources are entirely optional - you'd only use them if your layout needs to be very different from one configuration to another. ConstraintLayout, for instance, uses relative positioning (i.e., position a view relative to the parent or to another view), which is often quite flexible to different orientations, screen sizes, etc. thus removing any need to need an entirely different landscape layout for a simple layout.
Hopefully this is something simple and stupid. I am editing an existing Android app for an embedded device that communicates with Bluetooth. The manufacturer of the development kit provides the Android code so that you can edit it how you want. The device (Silabs Thunderboard Sense 2) just transfers numeric information (sensor data) from the device to the phone.
I have been able to edit the actual code to change labels and values to what I want, but now I want to rearrange/add/eliminate some buttons in the screen layout. The app generates these buttons when downloaded to the phone, but I'm unable to see them when I open the .xml files in "design view" in Android Studio. At first I thought the buttons weren't there at all, but then I noticed that there is a blue line down the left side of the sample screen. When I click on it, I get the attributes etc., but no matter what I try, I can't seem to get the button to show. I have tried pulling it, double-clicking it, right-clicking it, changing attributes...nothing works. I'm thinking that it's a setting that needs to be tweaked, but I'm afraid to just go changing everything and making it worse. Here is what it looks like:
the red circle indicates where the mysterious blue line appears.
It's like the image is scrunched to the left with no width. It should be a square image button with a small icon, a label and some live data. Any ideas?
Don
try setting the FrameLayout width policy to match_parent.
EDIT
Also check your parent LinearLayout width and height policy is `match_parent'.
I am learning to develop apps in android studio, and I am having some issues regarding the layout I am creating for my aps. I have 3x3 grid layout, and in each grid I placed an ImageView. Then I played around with margins to set up my app, however when it is displayed on the emulator, the margins are not in the places I put them. Here is a picture of my problem:
Why is this happening, and could someone help me in solving this?
In your layout editor you have the nexus 4 selected as the device for the screen size. You did not provide your layout code but I assume everything you did is static.
If your emulator is emulating another phone (a Nexus 5) with a different resolution and dpi, that could be the reason for the different layout.
im developing an android app on android studio, when i run my app the layout looks a bit different from the preview as well as on other phones,
for example: the buttons are in different order (from right to left instead from left to right) or other changes similar to this.
as well as on some phones the layout doesn't fit perfectly on the screen for example: the buttons on the sides of the screen appear to be cut out.
how can i fix it so the app will look the same with every phone and not only some of them?
About the Right-to-left/ Left-to-right, you can choose the globe icon in the preview options bar frame and then choose Preview Right-to-Left Layout option. This will "fix" the buttons order in preview.
About the buttons that appear to be cut out - make sure you use dp units instead of pixels. You can read more about it here:
http://developer.android.com/guide/practices/screens_support.html
Make sure you check if you have used the constraints on your components properly. Usually that's what makes the layout messy after running the app on your phone/emulator, even tho it looks perfect on your XML file.
so I'm making a really simple app that just shows some buttons and images,
it looks great on the simulator (because I guess that's the resolution I've been working on ...)
but when I try to build it to my phone it looks differently (the buttons are more stretched out and there is allot more background space in between the buttons and the end of the screen,
I guess it's something that's suppose to be simple but how to I make my app "zoom stretch" to the phone content it's going to be on, meaning it will look the same on any phone and if necessary will stretch the image a bit to fit the screen ?
Thx
In your XML, its important to not use specific(dp,px,etc.) sizes for laying buttons/text boxes/etc. out. For example, for a button thats on the page, use a "layout_width" of "match_parent" and add padding (if necessary from there). This will allow your button to stretch properly without having that extra whitespace.