2017-05-07 946 views
0

我在我的test_layout.xml中使用“android.support.constraint.ConstraintLayout”。Android。 ConstraintLayout:放置足够,但垂直滚动。为什么?

这里我的代码:

<?xml version="1.0" encoding="utf-8"?> 
    <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" 
    android:background="#aabbcc"> 

    <TextView 
     android:id="@+id/textView" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:background="#000000" 
     android:gravity="center" 
     android:text="Test text Test text Test text Test text Test text " 
     android:textColor="@android:color/white" 
     android:textSize="24sp" 
     app:layout_constraintBottom_toBottomOf="parent" 
     app:layout_constraintHorizontal_bias="0.0" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintTop_toTopOf="parent" 
     app:layout_constraintVertical_bias="0.18" /> 

    <ImageView 
     android:id="@+id/imageView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="8dp" 
     android:layout_marginRight="8dp" 
     android:layout_marginTop="8dp" 
     app:layout_constraintBottom_toBottomOf="parent" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintTop_toBottomOf="@+id/textView" 
     app:layout_constraintVertical_bias="0.0" 
     app:srcCompat="@drawable/input_checkmark_on_green" /> 

    <TextView 
     android:id="@+id/textView8" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:background="#ff0000" 
     android:gravity="center" 
     android:text="Test text Test text Test text Test text Test text Test text Test text Test text Test text Test text Test text Z" 
     android:textColor="@android:color/white" 
     android:textSize="18sp" 
     app:layout_constraintBottom_toBottomOf="parent" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintTop_toBottomOf="@+id/imageView" 
     app:layout_constraintVertical_bias="0.0" /> 

    <TextView 
     android:id="@+id/textView2" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:background="#000000" 
     android:gravity="center" 
     android:text="Test text Test text Test text Test text Test text Test text Test text Test text Test text Test text Test text Z" 
     android:textColor="@android:color/white" 
     android:textSize="18sp" 
     app:layout_constraintBottom_toBottomOf="parent" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintTop_toBottomOf="@+id/textView8" 
     app:layout_constraintVertical_bias="0.0" /> 

    <TextView 
     android:id="@+id/textView3" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:background="#ff0000" 
     android:gravity="center" 
     android:text="Test text Test text Test text Test text Test text Test text Test text Test text Test text Test text Test text Z" 
     android:textColor="@android:color/white" 
     android:textSize="18sp" 
     app:layout_constraintBottom_toBottomOf="parent" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintTop_toBottomOf="@+id/textView2" 
     app:layout_constraintVertical_bias="0.0" /> 

这里的结果(截图#1):

Before scroll vertically

正如你可以看到的地方就够了,但它veritically滚动。

见截图#2:

After scroll vertically

为什么它的垂直滚动?有足够的地方时,我不想垂直滚动。我如何做到这一点?

回答

0

我找到了解决办法。

替换:

这样的:

app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent"

通过

app:layout_constraintLeft_toLeftOf="@+id/textView" 
app:layout_constraintRight_toRightOf="@+id/textView" 

为项目下的所有项目。 “机器人:ID =” @ + ID/TextView的”作为结果 - 没有更多的垂直滚动

但是,为什么这个设置影响VE RTICAL滚动?