I am trying to place two Spinners
next to each other in a ConstraintLayout
. However, when I run the app on a real device, one of the spinners expands to the end of the screen and hides the other spinner. This works as expected in the Android Studio layout editor.
I have tried both with and without a CardView
, but the issue persists.I have tried various solutions, including setting the layout_width
of the Spinners
to wrap_content
, but the issue remains.When i replaced Spinner
with TextView
then it’s shows as i required How can I ensure that both spinners remain visible and are evenly spaced on the screen?
Here is my layout code:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/newPost_parent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:clickable="true"
android:fitsSystemWindows="true"
android:focusable="true"
android:focusableInTouchMode="true">
<Button
android:id="@+id/newPost_PostButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="@drawable/round_button_theme"
android:text="Post"
app:layout_constraintBottom_toTopOf="@id/newPost_statusText"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/newPost_userImage"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_margin="5dp"
app:layout_constraintEnd_toStartOf="@id/newPost_statusText"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/newPost_PostButton" />
<EditText
android:id="@+id/newPost_statusText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="@drawable/bottom_line_border"
android:hint="What's happening?"
android:maxLines="6"
android:minLines="3"
android:padding="10dp"
android:textColorHint="@color/black"
app:layout_constraintBottom_toTopOf="@id/newPost_preview"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/newPost_userImage"
app:layout_constraintTop_toBottomOf="@id/newPost_PostButton" />
<!--<com.google.android.material.textfield.TextInputLayout
android:id="@+id/newPost_statusText_TextInputLayout"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="What's happening?"
app:layout_constraintStart_toEndOf="@id/newPost_userImage"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="@id/newPost_preview">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/newPost_statusText"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:maxLines="6"
android:minLines="3"
android:padding="10dp"/>
</com.google.android.material.textfield.TextInputLayout>-->
<ImageView
android:id="@+id/newPost_preview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:minHeight="300dp"
android:scaleType="centerCrop"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/newPost_statusText"
/>
<ImageButton
android:id="@+id/newPost_cancelButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="@drawable/com_facebook_close"
app:layout_constraintEnd_toEndOf="@id/newPost_preview"
app:layout_constraintTop_toTopOf="@id/newPost_preview" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/newPost_galleryRecyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/newPost_audience" />
<TextView
android:id="@+id/newPost_addTags"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="@drawable/interest_background_unchecked"
android:padding="5dp"
android:text="Add Tags"
android:textAlignment="center"
android:textColor="@color/black"
android:textSize="14sp"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@id/newPost_audience"
app:layout_constraintStart_toStartOf="@id/newPost_preview"
app:layout_constraintTop_toBottomOf="@id/newPost_preview" />
<EditText
android:id="@+id/newPost_addTagsEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="@drawable/interest_background_unchecked"
android:hint="Add Tags"
android:padding="5dp"
android:paddingStart="10dp"
android:paddingEnd="10dp"
android:textColor="@color/black"
android:textSize="14sp"
android:visibility="gone"
app:layout_constraintBottom_toTopOf="@id/newPost_audience"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@id/newPost_preview"
app:layout_constraintTop_toBottomOf="@id/newPost_preview" />
<ImageView
android:id="@+id/newPost_audience"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:background="@drawable/post_audience"
app:layout_constraintEnd_toStartOf="@id/newPost_audienceCardView"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/newPost_addTags" />
<androidx.cardview.widget.CardView
android:id="@+id/newPost_audienceCardView"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintWidth_percent="20"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:padding="5dp"
app:cardBackgroundColor="@color/lightGray"
app:cardCornerRadius="18dp"
app:layout_constraintBottom_toBottomOf="@id/newPost_audience"
app:layout_constraintStart_toEndOf="@id/newPost_audience"
app:layout_constraintTop_toTopOf="@id/newPost_audience"
>
<androidx.appcompat.widget.AppCompatSpinner
android:id="@+id/newPost_audienceSpinner"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:dropDownWidth="match_parent"
android:prompt="@string/ppl_title"
android:spinnerMode="dropdown" />
</androidx.cardview.widget.CardView>
<ImageView
android:id="@+id/newPost_commentaudience"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_marginStart="20dp"
android:background="@drawable/comment_audience"
app:layout_constraintBottom_toBottomOf="@id/newPost_audienceCardView"
app:layout_constraintEnd_toStartOf="@id/newPost_CommentaudienceCardView"
app:layout_constraintStart_toEndOf="@id/newPost_audienceCardView"
app:layout_constraintTop_toTopOf="@id/newPost_audienceCardView" />
<androidx.cardview.widget.CardView
android:id="@+id/newPost_CommentaudienceCardView"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintWidth_default="wrap"
app:layout_constrainedWidth="true"
android:layout_marginStart="10dp"
android:layout_marginEnd="20dp"
android:padding="5dp"
app:cardBackgroundColor="@color/lightGray"
app:cardCornerRadius="18dp"
app:layout_constraintBottom_toBottomOf="@id/newPost_commentaudience"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/newPost_commentaudience"
app:layout_constraintTop_toTopOf="@id/newPost_commentaudience">
<androidx.appcompat.widget.AppCompatSpinner
android:id="@+id/newPost_CommentaudienceSpinner"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:dropDownWidth="match_parent"
android:prompt="@string/ppl_title"
android:spinnerMode="dropdown" />
</androidx.cardview.widget.CardView>
<ImageView
android:id="@+id/newPost_addImage"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginTop="10dp"
android:background="@drawable/post_image"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/newPost_addGIF"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/newPost_locationIcon" />
<ImageView
android:id="@+id/newPost_addGIF"
android:layout_width="24dp"
android:layout_height="24dp"
android:background="@drawable/post_gif"
app:layout_constraintBottom_toBottomOf="@id/newPost_addImage"
app:layout_constraintEnd_toStartOf="@id/newPost_addVideo"
app:layout_constraintStart_toEndOf="@id/newPost_addImage"
app:layout_constraintTop_toTopOf="@id/newPost_addImage" />
<ImageView
android:id="@+id/newPost_addVideo"
android:layout_width="24dp"
android:layout_height="24dp"
android:background="@drawable/post_video"
app:layout_constraintBottom_toBottomOf="@id/newPost_addGIF"
app:layout_constraintEnd_toStartOf="@id/newPost_addLocation"
app:layout_constraintStart_toEndOf="@id/newPost_addGIF"
app:layout_constraintTop_toTopOf="@id/newPost_addGIF" />
<ImageView
android:id="@+id/newPost_addLocation"
android:layout_width="24dp"
android:layout_height="24dp"
android:background="@drawable/post_location"
app:layout_constraintBottom_toBottomOf="@id/newPost_addVideo"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/newPost_addVideo"
app:layout_constraintTop_toTopOf="@id/newPost_addVideo" />
<ImageView
android:id="@+id/newPost_locationIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginTop="15dp"
android:background="@drawable/ic_location"
android:backgroundTint="@color/primary"
app:layout_constraintStart_toStartOf="@id/newPost_galleryRecyclerView"
app:layout_constraintTop_toBottomOf="@id/newPost_galleryRecyclerView" />
<TextView
android:id="@+id/newPost_addLocationToPost"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="Add location to this post"
android:textSize="12sp"
app:layout_constraintBottom_toBottomOf="@id/newPost_locationIcon"
app:layout_constraintStart_toEndOf="@id/newPost_locationIcon"
app:layout_constraintTop_toTopOf="@id/newPost_locationIcon" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_begin="20dp" />
<androidx.constraintlayout.widget.Group
android:id="@+id/group"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:constraint_referenced_ids="newPost_audience" />
</androidx.constraintlayout.widget.ConstraintLayout>