【发布时间】:2022-09-26 09:02:11
【问题描述】:
我正在尝试使用 ConstraintLayout 创建一个自定义 alertDialog,其中包含标题、带有 textview 的滚动视图和底部的按钮。
我希望滚动视图动态增长/缩小并填充标题和按钮之间的可用空间,这在预览中有效,但是在运行实际应用程序时,滚动视图和文本视图似乎实际上缩小到 0dp 并消失(据我所知它,带有 fillViewport 的 0dp 应该根据约束增长以适应可用空间。
布局:
<?xml version=\"1.0\" encoding=\"utf-8\"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"
android:layout_width=\"match_parent\"
android:layout_height=\"match_parent\"
xmlns:tools=\"http://schemas.android.com/tools\"
xmlns:app=\"http://schemas.android.com/apk/res-auto\"
android:background=\"@color/white\">
<TextView
android:id=\"@+id/tvTitle\"
android:layout_width=\"0dp\"
android:layout_height=\"wrap_content\"
android:text=\"A title\"
android:textSize=\"20dp\"
android:gravity=\"start\"
android:textColor=\"#000000\"
app:layout_constraintStart_toStartOf=\"parent\"
app:layout_constraintEnd_toEndOf=\"parent\"
app:layout_constraintTop_toTopOf=\"parent\"
/>
<ScrollView
android:id=\"@+id/svBody\"
android:layout_width=\"0dp\"
android:layout_height=\"0dp\"
android:fillViewport=\"true\"
app:layout_constraintTop_toBottomOf=\"@id/tvTitle\"
app:layout_constraintBottom_toTopOf=\"@id/btnClose\"
app:layout_constraintLeft_toLeftOf=\"parent\"
app:layout_constraintRight_toRightOf=\"parent\"
>
<TextView
android:id=\"@+id/tvBody\"
android:layout_width=\"match_parent\"
android:layout_height=\"wrap_content\"
android:text=\"AA text that is really long.A text that is really long.A text that is really long.A text that is really long.A text that is really long.A text that is really long.A text that is really long.A text that is really long.A text that is really long.A text that is really long.A text that is really long.A text that is really long.A text that is really long.A text that is really long.A text that is really long.A text that is really long.A text that is really long.A text that is really long.A text that is really long.A text that is really long.A text that is really long. text that is really long.\"
android:textSize=\"16dp\"
android:textColor=\"#000000\"
/>
</ScrollView>
<Button
android:id=\"@+id/btnClose\"
android:layout_width=\"100dp\"
android:layout_height=\"40dp\"
android:text=\"close\"
app:layout_constraintStart_toStartOf=\"parent\"
app:layout_constraintEnd_toEndOf=\"parent\"
app:layout_constraintBottom_toBottomOf=\"parent\"
android:layout_margin=\"5dp\"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
这可能是由于与稍后负责呈现此自定义警报对话框的视图的约束发生冲突引起的吗?还是我错过了其他东西?
我当然可以通过在 scrollView 上设置固定大小来解决它,但是在更大的屏幕上它看起来很小,所以我希望有一个动态的解决方案。
标签: android textview scrollview android-constraintlayout