代码之家  ›  专栏  ›  技术社区  ›  Hong

如何用动态内容约束滚动视图?

  •  0
  • Hong  · 技术社区  · 6 年前
    <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:layout_editor_absoluteY="25dp">
        <TableLayout
            android:id="@+id/tableLayoutHeader"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="16dp"
            android:layout_marginLeft="16dp"
            android:layout_marginTop="8dp"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/textViewDeviceName">
        </TableLayout>
    
        <ScrollView
            android:id="@+id/scrollViewLayoutFoo"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="8dp"
            android:layout_marginLeft="8dp"
            android:layout_marginTop="8dp"
            android:layout_marginBottom="8dp"
            android:minWidth="150dp"
            android:minHeight="60dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/tableLayoutHeader">
    
            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@color/red"
                android:orientation="vertical">
    
                <LinearLayout
                    android:id="@+id/linearLayoutFragments1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:orientation="vertical" />
    
    
                <LinearLayout
                    android:id="@+id/linearLayoutFragments2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:orientation="vertical"></LinearLayout>
            </LinearLayout>
    
        </ScrollView>
    </android.support.constraint.ConstraintLayout>
    

    有谁能提供一个如何解决这个问题的建议吗?

    1 回复  |  直到 6 年前
        1
  •  0
  •   TheLibrarian    6 年前

    你错过了一些限制。

    您需要将TabLayout限制为 起源 从“开始”/“顶部”/“结束”,并将“视图约束”滚动到其底部。

    <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">
    
        <TableLayout
            android:id="@+id/tableLayoutHeader"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginEnd="8dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="8dp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            tools:layout_height="48dp" />
    
        <ScrollView
            android:id="@+id/scrollViewLayoutFoo"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_marginBottom="8dp"
            android:layout_marginEnd="8dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="8dp"
            android:minHeight="60dp"
            android:minWidth="150dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/tableLayoutHeader">
    
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="#FF0000"
                android:orientation="vertical">
    
                <LinearLayout
                    android:id="@+id/linearLayoutFragments1"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical" />
    
    
                <LinearLayout
                    android:id="@+id/linearLayoutFragments2"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical" />
            </LinearLayout>
    
        </ScrollView>
    </android.support.constraint.ConstraintLayout>