enter image description here
Absolute beginner here, and I can't seem to access all of my options in android studio. For example, when I put in a textview in the layout, for the layout_width, fill parent option is not appearing, even though I definitely remember it to have been there when I used in briefly on my friend's computer.
It's not there as it's not an optimal option:
Important: MATCH_PARENT is not recommended for widgets contained in a
ConstraintLayout. Similar behavior can be defined by using
MATCH_CONSTRAINT with the corresponding left/right or top/bottom
constraints being set to "parent".
(source)
maybe you saw that option on a different layout (eg. linear).
Related
Every time I create views like Button and TextView in ConstraintLayout, they all get stuck at the top corner instead of where I placed them.
I tried to create new activities and change the emulator, but the result is still the same.
This is a screenshot of what's happening:
What may be the issue?
As stated in Constraint Layout guides:
If a view has no constraints when you run your layout on a device, it is drawn at position [0,0] (the top-left corner).
You must add at least one horizontal and one vertical constraint for the view.
I guess you haven't applied any constraints.
Either manually apply constraints to the view, or let the layout editor do it for you using "Infer constraints" button:
When you drop a view into the Layout Editor, it stays where you leave it even if it has no constraints... this is only to make editing easier
In other words, the View will "stay where you leave it" until you add constraints.
The reason it looks different in the Preview vs your app is because anything in your XML with tools: is going to be removed from the code when your app runs. These options are only for the Android Studio layout editor, not representative of what you should expect to see when the code runs.
And it may be troublesome for beginners because
a missing constraint won't cause a compilation error
However
the Layout Editor indicates missing constraints as an error in the toolbar. To view the errors and other warnings, click Show Warnings and Errors (red button with number). To help you avoid missing constraints, the Layout Editor can automatically add constraints for you with the Autoconnect and infer constraints features
More details
A quick, easy way to fix this is to click on the component (TextView, ImageView, etc.) and click the infer constraints button. It looks like 2 yellow plus signs.
infer constraints image
add this in xml to the button etc
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.57"
then play with it in the design.
Good luck! :)
Basically this type of problem happens when you use ConstraintLayout .
So Go to Preview From Android Studio.
Select That button you want to set at the specific position
At last just click the infer constrains button as i mention in
the picture below on a red circle.
Thats All run the project and see magic
Thank you
I just downloaded Android Studio and decided to try it out, never programmed in Java, or any kind of android app. It all seems good but once I emulated the app. I got weird formatting that wasn't a thing in app preview when I coded it. This is a simple "squaring" function app.
When I look at the preview:
When I emulate it:
You are getting this kind of formatting because you are using Constraint Layout as your root layout. There are no constraints to the views(EditText, Button and others) because of which they are placed at the top left corner of the screen.You have to add constraints in ContraintLayout.
Follow any of the three methods below-
Learn about Constraint Layout. Check out this link -Build a Responsive UI with ConstraintLayout in Android Studio (Most Useful of the three)
Change Constraint Layout to Linear Layout or Relative Layout as your root layout.(if you are familiar with them)
Click Infer Constraints (orange color two stars type symbol ) to automatically create constraints and compile again.(Simplest of the 3 methods for you right now)
I created an empty activity for 'My Testing App' and it looks like the following in the preview section:
But when I generated a build apk and used the same in my cell phone the result was like the following:
I can only view the exit button on the very top left but the two other buttons, that should be above it are missing.
I tried to rearrange the icons on the screen as well. I made them to go to the bottom, to the right most, but I see no change when the apk is reinstalled.
How do I make them visible on the hardware?
Here is the snap of the code for this activity:
To quickly add constraints to your layout just click on the Infer Constraints button in the Layout Editor toolbar. Learn more about the feature here: https://developer.android.com/training/constraint-layout/index.html#use-autoconnect-and-infer-constraints
Right Click on you Layout and select "Convert View" Option.
then select "LinearLayout" Option.
it will show all three buttons in the output.
You have to learn about ConstrainLayout in Android
View in ConstrainLayout is not only drag and drop. You should link the constrain line in each view to reference with somewhere on the screen.
Any XML attributes prefixed with tools are removed when the app is compiled and are only rendered by Android Studio layout editor.
You need to properly set constraints in your ConstraintLayout, not use absolute positioning.
Or you may instead use RelativeLayout, LinearLayout, etc.
https://developer.android.com/training/constraint-layout/index.html
Start by reading this. Most of what you need is answered here. The problem is that your views are not properly constrained (basically they aren't linked to anything so when you run your app it doesn't know where to place them and just defaults to the upper left).
I'm building an android project and I'm using eclipse.
I just can't figure out how to disable the annoying auto alignment.
I just want to place buttons wherever I want to drop them on the GUI interface but it just keeps
to align them one to another. I've tried to delete those alignment lines in the xml code
but it still brings them back as I move the buttons on the GUI interface.
Is there an way to disable that function?
Thank you,
Alex
Is there an way to disable that function?
Not in a way that you will find satisfactory, I suspect.
You have not really explained what the "alignment lines" are, so we are forced to guess. My guess is that the "alignment lines" are because you are working with a RelativeLayout container. Quoting the JavaDocs for RelativeLayout, RelativeLayout is:
A Layout where the positions of the children can be described in relation to each other or to the parent.
And, quoting the guide for RelativeLayout:
RelativeLayout is a view group that displays child views in relative positions. The position of each view can be specified as relative to sibling elements (such as to the left-of or below another view) or in positions relative to the parent RelativeLayout area (such as aligned to the bottom, left of center).
Hence, the "alignment lines" are there, and are replaced by the GUI builder, because they are the point behind using a RelativeLayout container.
Of course, you are welcome to change the container that you are working with to something else.
However, in general, Android does not really support very well your stated objective ("I just want to place buttons wherever I want to drop them on the GUI interface"). Just as you don't do that in Web development, you don't do that in Android development, and for much the same reason: you need to take different sizes into account (browser window size for Web, screen size for Android). RelativeLayout, LinearLayout, TableLayout, and GridLayout are all designed to have you specify widgets plus rules for positioning and sizing, so that you can design a UI that will accommodate the difference between a 3" and a 4.5" screen, for example. This is akin to using HTML tags and CSS rules to define content and its positioning in a Web page. Eclipse's drag-and-drop GUI builder for Android can assist in your definitions of these rules, as you are perhaps seeing with your "alignment lines" for RelativeLayout.
I think I may be able to help. If you set your layout to Relative Layout you can drag and drop any of the views wherever on the eclipse GUI.
we are confused with designing interface file for android,we have made user interface with Absolute layout and used "dip" instead of "px" (for different screen size issue) ,but it looks like,Absolute layout has been depreciated,and developer.android, recommends not to use Absolute layout
So other option we have is to use
1.Linear layout
2.Frame layout
3.Table Layout
But we are unable to bring Combination of above layouts so,that we can make button/widgets to proper position we need
How do we make widgets to desired position of screen with above said layouts and making them compatible with different screen sizes we have in android devices
would like to get a generic answer about same,
Tools used are: DrawDroid
The best layout to use if you were considering an AbsoluteLayout is a RelativeLayout.
Check out the Android Common Layout Objects page and its explanation of how to use a RelativeLayout.
Without more information on what you are trying to do, expanding this answer anymore is useless.