我正在尝试构建一个带有屏幕外元素的动态 ConstraintLayout,我可以稍后翻译它。但是,我无法让元素在屏幕外启动。
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<ImageView
android:id="@+id/onscreen_iv"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />
<ImageView
android:id="@+id/offscreen_iv"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toRightOf="parent" />
</android.support.constraint.ConstraintLayout>
通过将图像的左侧设置为全屏布局的右侧,图像应该位于屏幕外 - 不是吗?相反,结果是 offscreen_iv 直接位于 onscreen_iv 上方。编辑:如果我将 offscreen_iv 设置为 onscreen_iv 的右侧而不是父级的右侧,结果是相同的。
这似乎与将宽度设置为 match_parent 有关,就好像我将其设置为原始数字一样,它似乎可以工作,但尺寸当然是错误的。我需要我的图像是屏幕宽度。
感谢您的帮助!
最佳答案
有趣的问题。
我找到了一种让 offscreen_iv
消失的方法,即将您的图像放在 parent
之上。
您仍然可以保留您的 android:layout_width="match_parent"
试试这个:
<ImageView
android:id="@+id/offscreen_iv"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="parent" />
关于android - 如何将 ConstraintLayout 的子项放置在屏幕外(以便稍后可以将它们翻译到屏幕上)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63223477/