I am working on constraint layout I have three views. First is on top and 2nd have relative position to view1 and then last is below the view 2. Now in 2nd view I have textview which should be scrollable. Problem is scrollview height covering full screen but I want it to have fix height and do not move view 3 out of the screen. I do not want to hard code the height of scrollview so did know what should be the other way to solve it. In short 2nd view should remain between the view 1 and view 3 regardless of text length.
<android.support.constraint.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:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="20dp">
<ImageView
android:id="@+id/imageView"
android:layout_width="48dp"
android:layout_height="48dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/aandn_icon" />
<TextView
android:id="@+id/textView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:minHeight="48dp"
android:text="Lorem ipsum"
app:layout_constraintLeft_toRightOf="@+id/imageView"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="@+id/imageView" />
<ImageView
android:id="@+id/imageView2"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginTop="16dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView"
app:srcCompat="@drawable/aandn_icon" />
<ScrollView
android:id="@+id/scrolltext"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintLeft_toRightOf="@+id/imageView2"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="@+id/imageView2">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/start_tv4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/sound"
android:layout_gravity="top|left"
android:layout_toLeftOf="@+id/sound"
android:text="Definition: A happening or sudden event that is not wanted or expected.Example: The cars collided unexpectedly on the road causing an accident.||
Definition: A happening or sudden event that is not wanted or expected.Example: The cars collided unexpectedly on the road causing an accident.||
Definition: A happening or sudden event that is not wanted or expected.Example: The cars collided unexpectedly on the road causing an accident.||
Definition: A happening or sudden event that is not wanted or expected.Example: The cars collided unexpectedly on the road causing an accident.||
Definition: A happening or sudden event that is not wanted or expected.Example: The cars collided unexpectedly on the road causing an accident.||
Definition: A happening or sudden event that is not wanted or expected.Example: The cars collided unexpectedly on the road causing an accident.||
Definition: A happening or sudden event that is not wanted or expected.Example: The cars collided unexpectedly on the road causing an accident.||
Definition: A happening or sudden event that is not wanted or expected.Example: The cars collided unexpectedly on the road causing an accident.||
Definition: A happening or sudden event that is not wanted or expected.Example: The cars collided unexpectedly on the road causing an accident.||
Definition: A happening or sudden event that is not wanted or expected.Example: The cars collided unexpectedly on the road causing an accident.||
Definition: A happening or sudden event that is not wanted or expected.Example: The cars collided unexpectedly on the road causing an accident.||
Definition: A happening or sudden event that is not wanted or expected.Example: The cars collided unexpectedly on the road causing an accident.||
Definition: A happening or sudden event that is not wanted or expected.Example: The cars collided unexpectedly on the road causing an accident.||
Definition: A happening or sudden event that is not wanted or expected.Example: The cars collided unexpectedly on the road causing an accident.||
Definition: A happening or sudden event that is not wanted or expected.Example: The cars collided unexpectedly on the road causing an accident.||
Definition: A happening or sudden event that is not wanted or expected.Example: The cars collided unexpectedly on the road causing an accident.||
Definition: A happening or sudden event that is not wanted or expected.Example: The cars collided unexpectedly on the road causing an accident.||
Definition: A happening or sudden event that is not wanted or expected.Example: The cars collided unexpectedly on the road causing an accident.||
Definition: A happening or sudden event that is not wanted or expected.Example: The cars collided unexpectedly on the road causing an accident.||
"
android:textColor="#000000"
android:textSize="20sp" />
</android.support.constraint.ConstraintLayout>
</ScrollView>
<ImageView
android:id="@+id/imageView4"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginTop="16dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@+id/scrolltext"
app:srcCompat="@drawable/aandn_icon" />
<TextView
android:id="@+id/textView4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:minHeight="48dp"
android:text="Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. "
app:layout_constraintLeft_toRightOf="@+id/imageView4"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="@+id/imageView4" />
</android.support.constraint.ConstraintLayout>
this is the output
You want to stick textView4
to the bottom of the screen and let the ScrollView
fill in above that but below the top TextView
. If my understanding is correct, here is an approach:
To stick textView4
to the bottom of the screen:
<ImageView
android:id="@+id/imageView4"
...
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent" />
This is the image view, but the text view is tied to it.
To fill the center portion with the ScrollView
:
<ScrollView
android:id="@+id/scrolltext"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="@id/imageView4"
app:layout_constraintLeft_toRightOf="@+id/imageView2"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="@+id/imageView2"
app:layout_constraintVertical_bias="0.0">
The height of the scroll view is set to MATCH_CONSTRAINTS
(0dp) with the top and bottom constrained the scroll view's associated image view and the bottom image view. This will center the scroll view between those two constraints, so the vertical bias is needed to shift the scroll view to the top of the range.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With