如何在不丢失约束布局的情况下将所有视图放入可滚动视图中
How do i put al the views in a scrollable view without losing the constrain layout
我在 Google 上看到了多个示例,但我仍然无法在不丢失当前约束布局的情况下获得滚动视图。我想将所有文本视图(第一个除外)、文本编辑器和按钮放在滚动视图中。有人可以解释或展示如何做到这一点吗?提前致谢!
<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"
tools:context=".MainActivity">
<TextView/>
<EditText/>
<EditText/>
<EditText/>
<EditText/>
<EditText />
<EditText/>
<EditText/>
<EditText/>
<TextView/>
<TextView/>
<TextView/>
<TextView/>
<TextView/>
<TextView/>
<TextView/>
<TextView/>
<Button/>
</android.support.constraint.ConstraintLayout>
您可以将 ConstraintLayout
放在 ScrollView
中,例如:
<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:context=".MainActivity" />
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" />
... yours views ...
</android.support.constraint.ConstraintLayout>
</ScrollView>
如果您想在滚动之外保留一些视图,只需将 ScrollView
包装到另一个 ViewGroup
中,例如 android.support.constraint.ConstraintLayout
。
我不明白你的问题
这不适合你吗?
<LinearLayout>
<TextView/>
<ScrollView>
<ConstraintLayout>
<EditText/>
<EditText/>
<EditText/>
<EditText/>
<EditText />
<EditText/>
<EditText/>
<EditText/>
<TextView/>
<TextView/>
<TextView/>
<TextView/>
<TextView/>
<TextView/>
<TextView/>
<TextView/>
<Button/>
</ConstraintLayout>
</ScrollView>
</LinearLayout>
嗨,Doe,欢迎来到 Whosebug。我的方法是使用 RelativeLayout 作为主容器而不是 ConstraintLayout。 (为什么?)
因为这样很容易将 TextView 放在 ScrollView 之上,而将其他 TextView 和 EditText 放在里面!
我是这样做的:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/d"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:text="Example of the first TextView"
android:layout_height="wrap_content"
android:id="@+id/textView4" />
<ScrollView
android:layout_width="match_parent"
android:id="@+id/scrollViewExample"
android:layout_height="match_parent"
android:layout_below="@+id/textView4">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:text="Example of the other TextViews"
android:layout_height="wrap_content"
android:id="@+id/textView550" />
<TextView
android:layout_width="match_parent"
android:text="Example of the other TextViews"
android:layout_height="wrap_content"
android:id="@+id/textView540" />
</RelativeLayout>
</ScrollView>
</RelativeLayout>
祝你好运!
我在 Google 上看到了多个示例,但我仍然无法在不丢失当前约束布局的情况下获得滚动视图。我想将所有文本视图(第一个除外)、文本编辑器和按钮放在滚动视图中。有人可以解释或展示如何做到这一点吗?提前致谢!
<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"
tools:context=".MainActivity">
<TextView/>
<EditText/>
<EditText/>
<EditText/>
<EditText/>
<EditText />
<EditText/>
<EditText/>
<EditText/>
<TextView/>
<TextView/>
<TextView/>
<TextView/>
<TextView/>
<TextView/>
<TextView/>
<TextView/>
<Button/>
</android.support.constraint.ConstraintLayout>
您可以将 ConstraintLayout
放在 ScrollView
中,例如:
<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:context=".MainActivity" />
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" />
... yours views ...
</android.support.constraint.ConstraintLayout>
</ScrollView>
如果您想在滚动之外保留一些视图,只需将 ScrollView
包装到另一个 ViewGroup
中,例如 android.support.constraint.ConstraintLayout
。
我不明白你的问题 这不适合你吗?
<LinearLayout>
<TextView/>
<ScrollView>
<ConstraintLayout>
<EditText/>
<EditText/>
<EditText/>
<EditText/>
<EditText />
<EditText/>
<EditText/>
<EditText/>
<TextView/>
<TextView/>
<TextView/>
<TextView/>
<TextView/>
<TextView/>
<TextView/>
<TextView/>
<Button/>
</ConstraintLayout>
</ScrollView>
</LinearLayout>
嗨,Doe,欢迎来到 Whosebug。我的方法是使用 RelativeLayout 作为主容器而不是 ConstraintLayout。 (为什么?)
因为这样很容易将 TextView 放在 ScrollView 之上,而将其他 TextView 和 EditText 放在里面!
我是这样做的:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/d"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:text="Example of the first TextView"
android:layout_height="wrap_content"
android:id="@+id/textView4" />
<ScrollView
android:layout_width="match_parent"
android:id="@+id/scrollViewExample"
android:layout_height="match_parent"
android:layout_below="@+id/textView4">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:text="Example of the other TextViews"
android:layout_height="wrap_content"
android:id="@+id/textView550" />
<TextView
android:layout_width="match_parent"
android:text="Example of the other TextViews"
android:layout_height="wrap_content"
android:id="@+id/textView540" />
</RelativeLayout>
</ScrollView>
</RelativeLayout>
祝你好运!