ConstraintLayout - Adjust the view margins - android

I am trying to use the new features of how to build a layout in ConstraintLayout in Android Studio 2.2.
When I try to use Adjust the view margins nothing happens. Margins are not added to any View, neither of these that I have already added or those which I would like to add.
The margins change only when I change the parameters InControl the margin for each view in the Properties window for every View individually. Have you already used this feature?
Thanks in advance for your help.

The margin value in the toolbar applies to newly created connections (with the exception of connections to the parent). It's also the value we use when you use some of the placement tools (spread, etc.).

Related

ConstraintLayout views collapse [duplicate]

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

Blueprint view nor the constraints are now visible in Android Studio design view

I had to edit the Constraint Layout XML file by hand (*), so I also removed all the tools: fields from the XML. To my understanding these attributes are only used by Android Studio and the Constraint Layout tool. But I removed them because I wanted to reset the state of the layout and changing the android: properties for the Constraint Layout surely would only mix things up even more, right?
So I am now in a situation where the blueprint view stays empty and the hierarchy view says "Nothing to show". I see no view properties and no constraints. I can only see the flat UI design view of the layout, but I can't select any elements from it either.
Any ideas how to fix this?
I am running Android Studio 2.2.3 and Constraint Layout beta 4.
*) Why did I edit the layout by hand you ask? Well, I selected "Convert to Constraint Layout" in which case Android Studio just flattened my layout and hard coded the positions of all elements. Which wasn't exactly what I wanted since then I couldn't change the positions anymore. Removing the hard coded positions (and the tools: arguments) let me re-structure my layout.
Ok, I am going to answer this myself since I got it working thanks to Nicolas Roard who works on the Constraint Layout team at Google.
try pressing "r" [in the design view]
https://twitter.com/camaelon/status/809427379500126208
I wasn't aware of the keyboard shortcut "r" in this case, but it did solve it for me!

How to view all components of a scrollview

I have a scrollview with a lot of components in the layout that there is inside it. The result is like that:
I want to know if is there a way to view all components in Android Studio because I need to make changes in the design and currently, by this way it is so difficult.
Thanks for your help.
Set the android:scrollY property on the ScrollView, say 50dp in the beginning and then keep on increasing as you move further down. Make sure you remove this property before production ;)
Did you try to add a new device definition,
Setting it with a bigger height,
And using that one in your preview ?
I've just give it a try and it works nicely !
You should set gone property with for view on top of layout, so you can see view below to edit it.
Let fun with android studio preview!

Android: Adding a Button at a Specific Location

After reading the very helpful answer here: Why does LayoutInflater ignore the layout_width and layout_height layout parameters I've specified?, one thing I would like to add is to have a button (or any other View for that matter) be placed at a specific point on the screen.
You can use FrameLayout and specify margins for objects using parameters android:layout_marginRight, android:layout_marginBottom and so on. This will help you to set view position relative to the parent view.
You can also use AbsoluteLayout, but it is discouraged to do so. AbsoluteLayout was used when Android was supposed to work with the screens of a fixed resolution, and when this changed with Android 1.6, AbsoluteLayout became deprecated since it is inflexible and can't work properly on screens with different resolutions.
Hi you can use AbsoluteLayout for positioning a view to a particular location if you know the coordinate of the view.use this link for the overview of available layout.
http://mobiforge.com/designing/story/understanding-user-interface-android-part-1-layouts.

Android Eclipse ADT 8.0.0 (and 8.0.1) problem - can't create views hierarchy with drag and drop in the Outline view

Before the newest version I was able to create hierarchies using drag
n' drop, performed on the outline view.
Since the upgrade, I can't and the controls ('+', '-' and arrows) are
missing.
So how am I suppose to build view hierarchies now?
Drag the View to on of the edges you want to have that View on if you are using a RelativeLayout. That should work.
If you are using a LinearLayout you can just drag'n drop them as you are used to.
Apperantly that's a known issue and will be fixed in ADT 9.0. you can install experimental / nightly build of it now.
drag'n drop of views in a linear layout works... provided the layout is not empty and its heigth/width are not set to wrap_content !!!
example : create a linearLayout. Set the layout width / height to fill parent or some fixed value (e.g. 64dip). You can now drag'n drop, let's say, a textView in it.

Categories

Resources