Android 当根视图是滚动视图时,如何正确地在ConstraintLayout内创建视图以可见区域的百分比高度显示

Android 当根视图是滚动视图时,如何正确地在ConstraintLayout内创建视图以可见区域的百分比高度显示,android,android-layout,android-scrollview,android-coordinatorlayout,Android,Android Layout,Android Scrollview,Android Coordinatorlayout,我有这个层次的观点 ScrollView ConstraintLayout ImageView LinearLayout TextView TextView TextView ... 我想实现的是,ImageView垂直占据了可视屏幕的65%。。。但是由于根视图是滚动视图,ImageView占据了65%

我有这个层次的观点

ScrollView
        ConstraintLayout
            ImageView

            LinearLayout
                TextView
                TextView
                TextView
                ...
我想实现的是,ImageView垂直占据了可视屏幕的65%。。。但是由于根视图是滚动视图,ImageView占据了65%的可滚动区域。。。我希望ImageView占据65%的可见区域

为了得到这样的东西,最好的方法是什么

源代码:

<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>


提前感谢

在scrollview中,您不能将高度设置为百分比

我建议您使用纵横比来满足您的要求

在imageview中设置高度0dp并设置高度的尺寸比

android:layout_height="0dp"
app:layout_constraintDimensionRatio="H,1:1" //change ratio as per your image ratio

如果我用app:layout\u constraintDimensionRatio=“H,1:1”替换app:layout\u constraintheighth\u percent=“.65”,看起来很棒。。。除非有更好的答案,否则我会等上几个小时,然后把这个答案标记为接受答案。。但据我所知,这是最好的解决方案。