0

I have an activity that has one element that is rooted to the top, and another element that should take the rest of the space available. The first element's content will change over time and require different amounts of space, and the second element needs to change size with it. This is a simplified version of what I have already:

<android.support.constraint.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >

    <TextView
        android:id="@+id/textview_A"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintTop_toTopOf="parent"
        />

    <TextView
        android:id="@+id/textview_B"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintTop_toBottomOf="@+id/textview_A"
        app:layout_constraintBottom_toBottomOf="parent"
        />

</android.support.constraint.ConstraintLayout>

The way it is currently, the top element is correct, but the second element isn't. It will adjust its position to be halfway the bottom of the top element and the bottom of the parent element, but its height is the same as its content, not all available space. How can I achieve this?

3 Answers3

2

Set layout weight = 1 android: layout="1"

Vaibhav pandey
  • 109
  • 2
  • 6
1

Alternatively, try linearlayout like this:

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <EditText 
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="match_parent"
            android:text="text" />

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@mipmap/ic_launcher" />

        <Button 
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:text="D" />
    </LinearLayout>

notice this special snippet:

android:layout_width="0dp"
android:layout_weight="1"
Toma
  • 519
  • 7
  • 8
0

Please search before posting a question like this. Some of the previous answers on this


Change android:layout_height of @id/testview_B to 0dp. Something like
<TextView android:id="@+id/textview_B" android:layout_width="match_parent" android:layout_height="0dp" app:layout_constraintTop_toBottomOf="@id/textview_A" app:layout_constraintBottom_toBottomOf="parent" />

pellucide
  • 3,407
  • 2
  • 22
  • 25