I am doing a project using android studio. In android studio when I fix layout width
as matchparent
it automatically changes to 368dp
. I need layoutwidth
as matchparent
but changes by default.
why?
kindly help me to fix this problem.
I am doing a project using android studio. In android studio when I fix layout width
as matchparent
it automatically changes to 368dp
. I need layoutwidth
as matchparent
but changes by default.
why?
kindly help me to fix this problem.
Replace "match_parent" with "0dp" and add constraints to ConstraintLayout.
For example, a Button attached to bottom, height 50px and width that matches parent:
<Button
android:layout_width="0dp"
android:layout_height="50dp"
android:background="@color/azzurro"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:text="MY BUTTON"
/>
Probably because one of your parents is a ConstraintLayout.
https://developer.android.com/training/constraint-layout/index.html
If you don't want to deal with constraints just replace your ConstraintLayout with a FrameLayout or similar.
I had the the same issue and i was using ConstraintLayout. All i had to do to for android studio to stop rewriting my width was to ensure the
app:layout_constraintRight_toRightOf="parent"
is set to something in my case here i set it to parent