I have this hierarchy of views
ScrollView
ConstraintLayout
ImageView
LinearLayout
TextView
TextView
TextView
...
What I want to achieve is that the ImageView takes like 65% percent of the visible screen vertically... but since the root view is a ScrollView, the ImageView takes 65% of the scrollable area... I want the ImageView takes 65% of visible area.
What would be the best way to proced in order to get something like this?
Source code:
<ScrollView
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:fillViewport="true"
tools:context=".MainActivity">
<android.support.constraint.ConstraintLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="0dp"
android:scaleType="centerCrop"
android:src="@drawable/rain"
app:layout_constraintHeight_percent=".65"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/header">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="AAAAAA"
android:textSize="50dp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="BBBB"
android:textSize="50dp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="CCCCC"
android:textSize="50dp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="DDDDD"
android:textSize="50dp"/>
</LinearLayout>
</android.support.constraint.ConstraintLayout>
</ScrollView>
Thanks in advance
You can't set height as percentage when inside scrollview.
I have suggest you use Aspect ratio to match your requirements.
In your imageview set height 0dp & set dimension ratio for height.
android:layout_height="0dp"
app:layout_constraintDimensionRatio="H,1:1" //change ratio as per your image ratio