我有ScrollView以及其顶部和底部的其他几个视图,它位于ConstraintLayout内部。我尝试了很多方法,没有运气,Scrollview占用了整个空间而不是提供滚动,如果对底部视图提供约束,则该视图不可见。
XML文件:
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<!-- @style/Dialog.Title contains margins and font settings -->
<TextView
android:id="@+id/title_text_view"
style="@style/Dialog.Title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="0dp"
android:gravity="center_vertical"
android:text="@string/device_settings_quality_dialog_title"
app:layout_constraintBottom_toTopOf="@+id/quality_group_container"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
/>
<!-- @style/Dialog.Content contains only margins -->
<ScrollView
android:id="@+id/quality_group_container"
style="@style/Dialog.Content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/title_text_view"
app:layout_constraintBottom_toTopOf="@+id/cancel_button"
>
<RadioGroup
android:id="@+id/quality_radio_group"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Option 1">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Option 2">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Option 3">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Option 4">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Option 5">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Option 6">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Option 7">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Option 8">
</RadioGroup>
</ScrollView>
<!-- @style/Dialog.Actions.Button contains margins and paddings -->
<Button
android:id="@+id/cancel_button"
style="@style/Dialog.Actions.Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/device_settings_name_cancel_button_label"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
/>
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>
请帮我解决使用ConstraintLayout的问题。
答案 0 :(得分:0)
我希望此代码对您有所帮助
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
<!-- @style/Dialog.Title contains margins and font settings -->
<TextView
android:id="@+id/title_text_view"
style="@style/Dialog.Title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="0dp"
android:gravity="center_vertical"
android:text="@string/device_settings_quality_dialog_title"
app:layout_constraintBottom_toTopOf="@+id/quality_group_container"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
/>
<!-- @style/Dialog.Content contains only margins -->
<ScrollView
android:id="@+id/quality_group_container"
style="@style/Dialog.Content"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/title_text_view"
app:layout_constraintBottom_toTopOf="@+id/cancel_button">
<RadioGroup
android:id="@+id/quality_radio_group"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Option 1"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Option 2"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Option 3"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Option 4"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Option 5"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Option 6"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Option 7"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Option 8"/>
</RadioGroup>
</ScrollView>
<!-- @style/Dialog.Actions.Button contains margins and paddings -->
<Button
android:id="@+id/cancel_button"
style="@style/Dialog.Actions.Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/device_settings_name_cancel_button_label"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
</android.support.constraint.ConstraintLayout>
这里我设置了scrollview的属性如下
android:layout_height="0dp"
android:layout_weight="1"
这将为scrollview分配所有剩余空间