https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https%3A%2F%2Fbbear.kr%2Fandroid-maxHeight-1ce16f57eb5f4bb1a7897e176984d423&count_bg=%23000000&title_bg=%23000000&icon=&icon_color=%23FFFFFF&title=hits&edge_flat=false

maxHeight을 사용해본지 오래되었는데,

간단한 테스트용으로 쓸일이 생겨 아래와 같이 해보고자 했는데 잘 되지 않았다.

<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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:keepScreenOn="true"
    >
		<ScrollView
		        android:id="@+id/sv_message"
		        android:layout_width="0dp"
		        android:layout_height="wrap_content"
		        android:maxHeight="100dp"
		        app:layout_constraintBottom_toTopOf="@+id/et_message"
		        app:layout_constraintEnd_toStartOf="@+id/sv_local"
		        app:layout_constraintStart_toStartOf="parent">
		
		        <LinearLayout
		            android:orientation="vertical"
		            android:id="@+id/ll_message"
		            android:layout_width="match_parent"
		            android:layout_height="wrap_content"/>
		
		  </ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>

문제는, ConstraintLayout안에서 사용했기 때문인데,

아래와 같이 바꿔주면 된다.

<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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:keepScreenOn="true"
    >
		<ScrollView
		        android:id="@+id/sv_message"
		        android:layout_width="0dp"
		        android:layout_height="wrap_content"
**		        app:layout_constrainedHeight="true"
		        app:layout_constraintHeight_max="100dp"**
		        app:layout_constraintBottom_toTopOf="@+id/et_message"
		        app:layout_constraintEnd_toStartOf="@+id/sv_local"
		        app:layout_constraintStart_toStartOf="parent">
		
		        <LinearLayout
		            android:orientation="vertical"
		            android:id="@+id/ll_message"
		            android:layout_width="match_parent"
		            android:layout_height="wrap_content"/>
		
		  </ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>

출처

How to set max height to scrollView?

Powered by Fruition