android - 防止布局被推过某个边界
问题描述
我有一个 LinearLayout
app:layout_constraintDimensionRatio="1:2"
android:layout_width="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
在 ConstraintLayout 中。如果屏幕高度大于屏幕宽度的两倍,它看起来应该是这样。然而,在更宽的设备上,我的布局顶部被推出了屏幕。但是我希望顶部保持可见并让底部移出屏幕。这是我希望布局的行为方式:
1:足够长的设备,一切都很好:
2:设备稍宽一点,但一切正常:
3:更宽的设备,布局的顶部应该仍然可见,底部应该向下推:
解决方案
已解决:我确实将它放入 aScrollView
但为了app:layout_constraintDimensionRatio
也可以工作,我需要将实际内容放入 a ConstraintLayout
in 中ScrollView
:
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="bottom"
android:orientation="vertical">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/layoutBgSnakes"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="@+id/imgView"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="@id/imgView2"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:srcCompat="@drawable/..." />
<ImageView
android:id="@+id/imgView2"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:srcCompat="@drawable/..." />
</androidx.constraintlayout.widget.ConstraintLayout>
</RelativeLayout>
</ScrollView>
注意: android:fillViewport="true"
是使一切正常的关键线。
推荐阅读
- angular - 如何从商店中删除功能
- c - 每秒(或更少)将新文件写入磁盘是否会对硬件造成风险?
- react-native - 网络请求失败 Expo Fetch
- spring-boot - 在 Spring Boot 中用 @RestController 替换 @Controller 不会显示预期的视图
- python - 查找子列表的特定结果
- c# - 当我在 ASP.NET CORE Razor 中添加时,我在 ASP.NET 之外创建的 Html 和 Css 不适合
- wordpress - Wordpress 在简码中插入参数?
- sql - 从由开始行和结束行分隔的单个表中选择特定行
- excel - 通过 VBA 打开源工作簿时 VLookups 不更新
- php - 我如何将 MYSQL ROW_NUMBER OVER 与 MYSQL Server 而不是 MariaDB 一起使用