Couldn't change the height and width of a layout - android

In background it is listed as a constraintLayout , I am trying to insert a Linear Horizontal Layout over it. Whenever I assign match_parent to both android:layout_width and android:layout_height , it automatically reverts back to some Fixed Dp (like 395dp for width and 587dp for height) . How to change this setting?
Screenshot Here

Match parent won't work inside a constraint layout, you have to define the relative position inside the constraint layout. You have to assign the layout_constraintStart_toStartOf and layout_constraintEnd_toEndOf

Related

Android - fragments/custom views and layout width/height

When I create a layout for my fragment or my custom view I must define layout_width and layout_height. When I use this fragment or view in another layout, I must also define layout_width and layout_height.
Let's say that the root element of my fragment/view layout has layout_height="match_parent" and when I use this in another layout I have for example <fragment layout_height="wrap_content".
In this case the layout_height element is basically defined twice, once in the layout of the fragment/view itself and once in the layout where I'm using it, but with different values.
What happens to the value of layout_height of the root element of the fragment/view in this case? I don't understand how this works... does one override the other?
when you are using match_parent for parent layout it matches the parent width/height.Now when you are using another layout inside this parent layout
1.if you are setting wrap_content it will not totally use the height/width of parent as it's set to wrap_content
2.setting child layout width/height to match_parent then the child layout will stretch to entire parent limits

Change ConstraintLayout default margin

When we create a constraint to a view through the designer, it automatically creates margin for this constraint - 8dp. There are a lot of cases when I don't need that margin, so I have to manually remove it (or change to 0dp).
Is there a way we can customize a default margin for a constraint in ConstraintLayout ?
For ConstraintLayout child's you can set default margin like is shown on the image.

Button are getting overlapped on deifferent devices using dp in relative layout

left one is the mobile phone and right one is the device on android studio.
Use linear layout (horizontal) inside your relative layout and add buttons to it
Set linear layout's attribute weight_sum to number of buttons in a row (for example 5)
Set buttons' attribute layout_weight instead of explicitly defining size in dp (for example 1 for each button)
Duplicate your linear layout for all the rows
Profit

Android ScrollView's ContentViewGroup's Child not respecting match_parent

I have a layout which look like the following:
ScrollView(match_parent, match_parent)
- RelativeLayout(match_parent, 1000dp)
- ImageView(match_parent, match_parent)
The problem is that ImageView's height is not matching parent when it is being layout.
Anyone know why this is happening and any solution?
A ScrollView will automatically force its child to wrap its content, no matter whether you tell it to FILL_PARENT or MATCH_PARENT or specify any other size... Thats why it is not working...

Hierachy of android:layout_width/ height between containers and views

What is the relationship between android:layout_width & android:layout_height in the container and the views contained within?
For instance if I have a LinearLayout with the layout width and height set to fill_parent, and I have a Button with those values set to wrap_content it uses the value from the Button, like the Button values overide the LinearLayout.
However if i swap them around so that the LinearLayout values are both wrap_content and the Button values are now fill_parent it still uses wrap_content, this time not overriding the values, but using the values supplied with the LinearLayout.
Could someone explain how they relate as this is very confusing to me?
Thanks
Kyros
http://developer.android.com/guide/topics/ui/how-android-draws.html
This article explains it very well

Categories

Resources