Set*_*ter 80 user-interface android android-layout android-constraintlayout
所以最近,与Android Studio 2.2中有一个新的ConstraintLayout,使设计轻松了很多,但不像RelativeLayout
并且Linearlayout
,我不能使用ScrollView
包围ConstraintLayot
.这可能吗?如果是这样,怎么样?
即
<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"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="0dp">
<android.support.constraint.ConstraintLayout
android:id="@+id/constraintLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="0dp">
<!-- Have whatever children you want inside -->
</android.support.constraint.ConstraintLayout>
</ScrollView>
Run Code Online (Sandbox Code Playgroud)
eri*_*gor 197
尝试添加android:fillViewport="true"
到ScrollView.
在这里找到解决方案:LinearLayout不在ScrollView中扩展
Raj*_*olf 47
NestedScrollView
与viewport一起使用true对我有用
<android.support.v4.widget.NestedScrollView
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="700dp">
</android.support.constraint.ConstraintLayout>
</android.support.v4.widget.NestedScrollView>
Run Code Online (Sandbox Code Playgroud)
Gov*_*wal 32
ScrollViews中存在ConstraintLayout的错误,并且已修复.谷歌修复了Android Studio 2.2 Preview 2中的错误(constraintlayout 1.0.0-alpha2).
检查此链接是否有新更新(预览2):在ScrollView和RecycleView中正常工作
Pra*_*iya 12
NestedScrollView
与使用android:fillViewport="true"
<android.support.v4.widget.NestedScrollView
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">
<!--Edit your stuff-->
</android.support.constraint.ConstraintLayout>
</android.support.v4.widget.NestedScrollView>
Run Code Online (Sandbox Code Playgroud)
Sak*_*yed 10
设置ScrollView
layout_height
为a wrap_content
然后它将正常工作.以下是可以帮助某人的例子.我用于compile 'com.android.support.constraint:constraint-layout:1.0.2'
约束布局.
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
android:orientation="vertical"
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:id="@+id/activity_main"
tools:context=".ScrollViewActivity">
<ScrollView
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
>
<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="wrap_content"
android:orientation="vertical"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:scrollbars="vertical">
<TextView
android:id="@+id/tvCommonSurname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="surname"
android:textAppearance="?android:attr/textAppearanceLarge"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:layout_constraintLeft_creator="1"
tools:layout_constraintTop_creator="1" />
<EditText
android:id="@+id/editText3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:ems="10"
android:inputType="text"
android:maxLines="1"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tvCommonSurname"
tools:layout_constraintLeft_creator="1"
tools:layout_constraintRight_creator="1"
tools:layout_constraintTop_creator="1" />
<TextView
android:id="@+id/tvCommonName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="firstName"
android:textAppearance="?android:attr/textAppearanceLarge"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@+id/editText3"
tools:layout_constraintLeft_creator="1"
tools:layout_constraintTop_creator="1" />
<EditText
android:id="@+id/editText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:ems="10"
android:inputType="text"
android:maxLines="1"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tvCommonName"
tools:layout_constraintLeft_creator="1"
tools:layout_constraintRight_creator="1"
tools:layout_constraintTop_creator="1" />
<TextView
android:id="@+id/tvCommonLastName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="middleName"
android:textAppearance="?android:attr/textAppearanceLarge"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@+id/editText"
tools:layout_constraintLeft_creator="1"
tools:layout_constraintTop_creator="1" />
<EditText
android:id="@+id/editText2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:ems="10"
android:inputType="text"
android:maxLines="1"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tvCommonLastName"
tools:layout_constraintLeft_creator="1"
tools:layout_constraintRight_creator="1"
tools:layout_constraintTop_creator="1" />
<TextView
android:id="@+id/tvCommonPhone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="Phone number"
android:textAppearance="?android:attr/textAppearanceLarge"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@+id/editText2"
tools:layout_constraintLeft_creator="1"
tools:layout_constraintTop_creator="1" />
<EditText
android:id="@+id/editText4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:digits="0123456789"
android:ems="10"
android:inputType="phone"
android:maxLength="10"
android:maxLines="1"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tvCommonPhone"
tools:layout_constraintLeft_creator="1"
tools:layout_constraintRight_creator="1"
tools:layout_constraintTop_creator="1" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="sex"
android:textAppearance="?android:attr/textAppearanceLarge"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@+id/editText4"
tools:layout_constraintLeft_creator="1"
tools:layout_constraintTop_creator="1" />
<RadioGroup
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/radiogroup"
android:layout_width="0dp"
android:layout_height="48dp"
android:layout_marginTop="8dp"
android:orientation="horizontal"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView3"
tools:layout_constraintLeft_creator="1"
tools:layout_constraintTop_creator="1">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="pirates" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ninjas" />
</RadioGroup>
<TextView
android:id="@+id/tvCommonDOB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="dob"
android:textAppearance="?android:attr/textAppearanceLarge"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@+id/radiogroup"
tools:layout_constraintLeft_creator="1"
tools:layout_constraintTop_creator="1" />
<EditText
android:id="@+id/editText5"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:ems="10"
android:inputType="date"
android:maxLines="1"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tvCommonDOB"
tools:layout_constraintLeft_creator="1"
tools:layout_constraintRight_creator="1"
tools:layout_constraintTop_creator="1" />
<TextView
android:id="@+id/tvCommonLivingCity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="livingCity"
android:textAppearance="?android:attr/textAppearanceLarge"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@+id/editText5"
tools:layout_constraintLeft_creator="1"
tools:layout_constraintTop_creator="1" />
<EditText
android:id="@+id/editText34"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:ems="10"
android:inputType="text"
android:maxLines="1"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tvCommonLivingCity"
tools:layout_constraintLeft_creator="1"
tools:layout_constraintRight_creator="1"
tools:layout_constraintTop_creator="1" />
<TextView
android:id="@+id/tvCommonPlaceOfBithday"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="placeOfBirth"
android:textAppearance="?android:attr/textAppearanceLarge"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@+id/editText34"
tools:layout_constraintLeft_creator="1"
tools:layout_constraintTop_creator="1" />
<EditText
android:id="@+id/editText6"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:ems="10"
android:inputType="text"
android:maxLines="1"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tvCommonPlaceOfBithday"
tools:layout_constraintLeft_creator="1"
tools:layout_constraintRight_creator="1"
tools:layout_constraintTop_creator="1" />
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="education"
android:textAppearance="?android:attr/textAppearanceLarge"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@+id/editText6"
tools:layout_constraintLeft_creator="1"
tools:layout_constraintTop_creator="1" />
<Spinner
android:id="@+id/spinner_id"
android:layout_width="0dp"
android:layout_height="48dp"
android:layout_marginTop="8dp"
android:spinnerMode="dialog"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView4"
tools:layout_constraintLeft_creator="1"
tools:layout_constraintRight_creator="1"
tools:layout_constraintTop_creator="1" />
</android.support.constraint.ConstraintLayout>
</ScrollView>
</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)
尝试为您的约束布局提供一些填充底部,如下所示
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/top"
android:fillViewport="true">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="100dp">
</android.support.constraint.ConstraintLayout>
</ScrollView>
Run Code Online (Sandbox Code Playgroud)
任何将以下属性设置为
滚动视图::android:fillViewport="true"
约束布局: android:layout_height="wrap_content"
并且它仍然不起作用然后确保您没有将内部可滚动布局(RecycleView)底部约束设置为父级的底部。
添加以下代码行:
android:nestedScrollingEnabled="false"
android:layout_height="wrap_content"
Run Code Online (Sandbox Code Playgroud)
确保删除以下约束:
app:layout_constraintBottom_toBottomOf="parent"
Run Code Online (Sandbox Code Playgroud)
完整代码
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/selectHubLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context=".ui.hubs.SelectHubFragment">
<include
android:id="@+id/include"
layout="@layout/signup_hub_selection_details"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_HubSelection"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:nestedScrollingEnabled="false"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/include" />
</androidx.constraintlayout.widget.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
78826 次 |
最近记录: |