skip to Main Content
<androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >
    <Button
        android:id="@+id/open_explanation_button"
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:background="@drawable/open_dialog"
        app:layout_constraintEnd_toEndOf="parent"
        />
    <TextView
        android:id="@+id/movieRatingText"
        android:layout_width="match_parent"
        android:layout_height="30dp"
        android:gravity="center"
        android:layout_weight="53"
        android:text="Rating: R"
        android:textColor="@color/white"
        android:textSize="20sp"
        app:autoSizeMaxTextSize="100sp"
        app:autoSizeMinTextSize="12sp"
        app:autoSizeStepGranularity="2sp"
        app:autoSizeTextType="uniform"
        app:layout_constraintTop_toBottomOf="@+id/inASeriesOrNoText"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        />

I have a button with an id of open_explanation_button, I need to place that button to the end of the movieRatingText. The problem is that I need the movieRatingText to be with a width of match_parent to make sure that it’s an autoresizable text. In a more simpler way, I need to constraint the start of the open_explanation_button to the center of the movieRatingText, in addition to adding some margins.
Any help?

2

Answers


  1. You have to constraint end and start of your view, to its parent

    Login or Signup to reply.
  2. You can create a dummy view and align that as the center point of movieRatingText. And use that to start of open_explanation_button

       <androidx.constraintlayout.widget.ConstraintLayout 
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    
    <Button
        android:id="@+id/open_explanation_button"
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:background="@drawable/ic_add"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="@id/centerView" />
    
    <TextView
        android:id="@+id/movieRatingText"
        android:layout_width="match_parent"
        android:layout_height="30dp"
        android:layout_weight="53"
        android:gravity="center"
        android:text="Rating: R"
        android:textColor="@color/white"
        android:textSize="20sp"
        app:autoSizeMaxTextSize="100sp"
        app:autoSizeMinTextSize="12sp"
        app:autoSizeStepGranularity="2sp"
        app:autoSizeTextType="uniform"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/inASeriesOrNoText"
        app:layout_constraintTop_toTopOf="parent" />
    
    <View
        android:id="@+id/centerView"
        android:layout_width="1dp"
        android:layout_height="1dp"
        app:layout_constraintEnd_toEndOf="@id/movieRatingText"
        app:layout_constraintStart_toStartOf="@id/movieRatingText"
        app:layout_constraintTop_toTopOf="@+id/movieRatingText" />
    

    </androidx.constraintlayout.widget.ConstraintLayout>

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search