I am doing a project using android studio. In android studio when I fix layout width as matchparentit 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 matchparentit automatically changes to 368dp. I need layoutwidth as matchparent but changes by default.
why?
kindly help me to fix this problem.
On
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
<android.support.constraint.ConstraintLayout
android:id="@+id/activity_content"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!--header row-->
<include
android:id="@+id/content_header"
layout="@layout/adapter_fish_row_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginLeft="4dp"
android:layout_marginTop="8dp"
android:layout_marginStart="4dp"
android:layout_marginRight="4dp"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintHorizontal_bias="0.0" />
<!-- The main content view -->
<android.support.v7.widget.RecyclerView
android:id="@+id/fish_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@+id/content_header"
android:layout_marginLeft="4dp"
android:layout_marginTop="8dp"
android:layout_marginStart="4dp"
android:layout_marginRight="4dp"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintHorizontal_bias="0.0" />
<Button
android:id="@+id/form_submit_button"
style="@style/form_submit_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="4dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:layout_marginStart="4dp"
android:background="@color/primary"
android:text="@string/btn_next_page"
android:textColor="@color/text_primary"
app:layout_constraintHorizontal_bias="0.496"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginTop="8dp"
app:layout_constraintTop_toBottomOf="@+id/fish_list" />
</android.support.constraint.ConstraintLayout>
On
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.