2017-10-09 11 views
5

NestedScrollViewの中にあります。 ConstraintLayoutには一連のビューが含まれていますが、最後のViewは、スペースがない場合は底部スペースを埋めるために動的な高さを持つことができますが、最小の高さにする必要があります。ConstraintLayoutでminHeightで表示

議論のために、ここに例があります。

ご覧のとおり、私はConstraintLayoutバージョンを入れましたが、動作しません。明らかに値はばかげて大きいですが、これはテスト用です。

私はNestedScrollViewその後、ConstraintLayoutfillViewport="true"を設定しない場合は、スクロールしないConstraintLayoutを私はfillViewportを設定しない0の高さを持っていますが、単に画面を埋めます。

ConstraintLayoutの下部に拡大するようにビューを設定するにはどうすればよいですか?ビューは、minHeightではない場合、スクロールを許可しますか?

ConstraintLayoutのバージョン1.0.2を使用しています。

私は、親の一番下まで来ていることを期待していますが、そのサイズが1500dpより小さい場合は、ビューがスクロールします。

android:layout_height="1500dp"のように私は1500dpに入っており、それに応じてビューがスクロールします。

UPDATE 1

は私がFragmentViewPager内のレイアウトを入れたら、しているようです。 app:layout_constraintHeight_minプロパティは尊重されず、ビューポートの高さにのみ一致します。

また、NestedScrollViewをフラグメントから取り出して、ViewPagerを入れてみましたが、もう一度動作しませんでした。私はcom.android.support.constraint:constraint-layout:1.0.2を使用していますが、これは私の作品

+0

「ConstraintLayout」のどのバージョンを使用していますか? – Cheticamp

答えて

6

あなたはストレッチをしたいのです表示するには、この属性を追加します。

app:layout_constraintHeight_default="spread" 

私は証明するために小さなアプリを作りました。何のJavaの話をするためのロジックませんが、ここではレイアウトです:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.widget.NestedScrollView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fillViewport="true"> 

    <android.support.constraint.ConstraintLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:padding="16dp" 
     android:background="#caf"> 

     <TextView 
      android:id="@+id/one" 
      android:layout_width="0dp" 
      android:layout_height="48dp" 
      android:gravity="center" 
      android:text="hello world" 
      android:background="#fff" 
      app:layout_constraintTop_toTopOf="parent" 
      app:layout_constraintLeft_toLeftOf="parent" 
      app:layout_constraintRight_toRightOf="parent" 
      app:layout_constraintBottom_toTopOf="@+id/two"/> 

     <TextView 
      android:id="@+id/two" 
      android:layout_width="0dp" 
      android:layout_height="48dp" 
      android:gravity="center" 
      android:text="hello world" 
      android:background="#eee" 
      app:layout_constraintTop_toBottomOf="@+id/one" 
      app:layout_constraintLeft_toLeftOf="parent" 
      app:layout_constraintRight_toRightOf="parent" 
      app:layout_constraintBottom_toTopOf="@+id/three"/> 

     <TextView 
      android:id="@+id/three" 
      android:layout_width="0dp" 
      android:layout_height="0dp" 
      android:gravity="center" 
      android:text="hello world" 
      android:background="#ddd" 
      app:layout_constraintHeight_default="spread" 
      app:layout_constraintHeight_min="300dp" 
      app:layout_constraintTop_toBottomOf="@+id/two" 
      app:layout_constraintLeft_toLeftOf="parent" 
      app:layout_constraintRight_toRightOf="parent" 
      app:layout_constraintBottom_toBottomOf="parent"/> 

    </android.support.constraint.ConstraintLayout> 

</android.support.v4.widget.NestedScrollView> 

底面図は、それが残りの利用可能なスペースよりも小さい場合には、ビューポートを埋めるために伸び、およびスクロールが不可能である:

enter image description here

がスクロールを可能に残りの利用可能なスペースよりも大きい場合底面図は一定の高さを維持する:

enter image description hereenter image description here

+0

これは正解であるように見えます。 – azizbekian

+0

徹底的な答えをありがとう。制約レイアウトがうまくいかない理由をデバッグするためにあなたの答えを使用し、異なる制約を持つ他のビューがうまくいきませんでした。私はこれらの他のビューが制約された方法を変え、それが働き始めました。私の次の問題は、私が私のViewPagerに入れたときにうまくいかない理由です... – StuStirling

+0

これは問題を引き起こしている 'ViewPager'のようです – StuStirling

0

<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

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

     <View 
      android:layout_width="0dp" 
      android:layout_height="0dp" 
      android:background="@drawable/gradient" 
      app:layout_constraintBottom_toBottomOf="parent" 
      app:layout_constraintEnd_toEndOf="parent" 
      app:layout_constraintHeight_min="1500dp" 
      app:layout_constraintStart_toStartOf="parent" 
      app:layout_constraintTop_toTopOf="parent" /> 

    </android.support.constraint.ConstraintLayout> 

</android.support.v4.widget.NestedScrollView> 
0

まず最初に、私たちは、制約レイアウト内の別のoption.Secondaryプロパティアプリとして各テキストビューに一定の高さや使用ラップコンテンツを指定する必要があるとして:layout_constraintHeight_defaultは=「広がり」をは、取得するための最後のビューを支援空き領域が残っていなければ自動的にスクロールビューに同期されます。

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.widget.NestedScrollView 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:fillViewport="true"> 
<android.support.constraint.ConstraintLayout 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:background="#caf" 
android:padding="16dp"> 
<TextView 
android:id="@+id/one" 
android:layout_width="0dp" 
android:layout_height="48dp" 
android:background="#fff" 
android:gravity="center" 
android:text="hello world" 
app:layout_constraintBottom_toTopOf="@+id/two" 
app:layout_constraintLeft_toLeftOf="parent" 
app:layout_constraintRight_toRightOf="parent" 
app:layout_constraintTop_toTopOf="parent" /> 
<TextView 
android:id="@+id/two" 
android:layout_width="0dp" 
android:layout_height="48dp" 
android:background="#eee" 
android:gravity="center" 
android:text="hello world" 
app:layout_constraintBottom_toTopOf="@+id/three" 
app:layout_constraintLeft_toLeftOf="parent" 
app:layout_constraintRight_toRightOf="parent" 
app:layout_constraintTop_toBottomOf="@+id/one" /> 
<TextView 
android:id="@+id/three" 
android:layout_width="0dp" 
android:layout_height="48dp" 
android:background="#eee" 
android:gravity="center" 
android:text="hello world" 
app:layout_constraintBottom_toTopOf="@+id/four" 
app:layout_constraintLeft_toLeftOf="parent" 
app:layout_constraintRight_toRightOf="parent" 
app:layout_constraintTop_toBottomOf="@+id/two" /> 
<TextView 
android:id="@+id/four" 
android:layout_width="0dp" 
anroid:layout_height="48dp" 
android:background="#eee" 
android:gravity="center" 
android:text="hello world" 
app:layout_constraintBottom_toTopOf="@+id/five" 
app:layout_constraintLeft_toLeftOf="parent" 
app:layout_constraintRight_toRightOf="parent" 
app:layout_constraintTop_toBottomOf="@+id/three" /> 
<TextView 
android:id="@+id/five 
android:layout_width="0dp" 
android:layout_height="0dp" 
android:background="#ddd 
android:gravity="center" 
android:text="hello world" 
app:layout_constraintBottom_toBottomOf="parent" 
app:layout_constraintHeight_default="spread" 
app:layout_constraintHeight_min="300dp" 
app:layout_constraintLeft_toLeftOf="parent" 
app:layout_constraintRight_toRightOf="parent" 
app:layout_constraintTop_toBottomOf="@+id/three" /> 
</android.support.constraint.ConstraintLayout> 
</android.support.v4.widget.NestedScrollView> 
関連する問題