Android studio - TextView showing on preview but not emulator/device - android

I started the "Android 6 for Programmers: An App-Driven Approach" book and ran into a problem. I was following the step-by-step approach for one of the apps and got a pretty frustrating error that I cannot fix.
I've added a text and image views and on the Preview section they are shown as they should be but when I run the app on the emulator or on an actual device the text seem to be missing. I am going to attach photos below for more clarity.
The custom colour is Material Blue 500 (#2196F3). Tried changing it to another but the problem doesn't seem to be affected by it.
The text size is 40sp (80sp on a > 600x600 device).

You need to change tools:text to android:text. Using tools attribute you can only see preview in design time.

Try to remove Layout weight, it might be the problem .

When using a LinearLayout and layout weights, set height in your case to 0dp for both the text and image
If you're wanting to center things and align to each other, RelativeLayout or ConstraintLayout would be preferred.

Related

Difference between design in preview and android virtual device

Image of XML code and Design Differnce
In this there is a space left right of the image in AVD but in preview, space is fully covered for ImangeView
Same in case if TextView
I want the AVD design same as Preview. Is there any solution of the problem please help
You have to set the layout_centerOrizontal in "true" for each graphical component. It will solve the question of horizontal align issue. But, the preview cannot show all the devices, have this in mind. So, you have to predict somehow to achieve better performance for differents functions and diffents devices.
In your case, with your example, you have to make the all components be on the center (i'm guessing that is what you want). You can work with padding too. So in order to fill the space in a better way (not too empty, like the space below the images on the first image), you can use margin and padding settings that can bring a better looking.

How can manage layout screen for all android phone?

I have two cell phones.When I run same app on both phone is not properly work. For fix that problem i use sw120dip and sw360dip layout. But i cant solve this error.
How can i solve this error.
Use the Relative layout by the way if you are using other layout and design it with the Android Studio Design instead of using xml .In this way you can see the layout of screen without running the app on real phone.
If you use relative layout with all dimensions in "dp" and font sizes in "sp" then it has to fit in all screen size. I have never seen scenario unless one is using fixed layout. Pls paste your layout to get more details about your questions.

Android Preview vs Emulator Layout Size

Folks,
I cant design my android screens and see it on my emulator somehow the resolution, zoom (whatever) in the emulator is big and my layout is messed up.
The whole layout is inside a FrameLayout, the paragraph text in the emulator pic is inside a RelativeLayout, which is set to GONE after users upload rating, then LinearLayout shows up with the overall rating bar in the some place where the RelativeLayout was.
My question is why is this happening since in the preview it seems perfect and on the emulator it seems all messed.
Please see the screenshots:
Android Studio Preview:
Genymotion Emulator
It is really hard to determine what exactly is wrong without seeing your xml markup.
Possible Reasons
You gave your layouts some sort of fixed size, and therefore it appears to be fine on your markup, but whatever you are emulating on Genymotion is using a different ratio.
When you do a View.GONE, you say you are replacing a RelativeLayout with a LinearLayout. Well, do you make sure that the layout that is replaced is layoutAbove whatever that frame layout below it is?
Some layout just has some attribute, like an alignment issue, that is causing this.
Trace your steps backwards, removing one thing at a time. Get it to work with that view gone first, then add it and manipulate it after.

layout on android studio preview doesn't look the same when running the app on the phone

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.

Roboto inconsistent font height

I'm currently facing strange problems with Android's font Roboto. At first I had two TextViews in one horizontal LinearLayout, centered both vertically and horizontally. The first TextView was set font Roboto-Black.ttf and the second was Roboto-Light.ttf. Both was set to textSize="12sp", but the one with Roboto-Light.ttf was just a pixel higher then the Roboto-Black.ttf TextView. But it didn't happen when I've set textSize="13sp". So I've created new Android project, just to be sure it's not only in the one application. The result is almost identical, but in this case, textSize="12sp" works as expected but textSize="13sp" doesn't. I've made screenshots to show the issue.
12sp works as expected. Top edges align.
13sp has this strange behavior.
Strange is, that this happens only when I try to mix thin and thick lined variants. When I make one TextView Roboto-Bold.ttf and second Roboto-Black.ttf, result is good. When I try Roboto-Light.ttf and Roboto-Thin.ttf, it also work properly.
So I also tried to test this in photoshop and this is what I found:
It's the same for all fonts from Roboto family, except for the Roboto-Light.ttf. I can also post source code for the layout if needed.
Thanks in advance.
PS: I'm sorry for the links but due to low reputation (brand new account) I can't post images. Also in the last link i had to remove the "h" from "http", because it didn't allow me more than two links.
I can't tell you if its the fonts or how your phone interprets the fonts and displays them on the screen but I can tell you that I've had issues with centering views in the middle before.
Have you tried using a relativelayout and then align the second textviews top and bot with the first textview? That might solve the problem.

Categories

Resources