android - 如何将 ConstraintLayout 的子项放置在屏幕外(以便稍后可以将它们翻译到屏幕上)?

标签 android xml android-layout android-constraintlayout

我正在尝试构建一个带有屏幕外元素的动态 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/

相关文章:

Java Android、倒数计时器和 ProgressBar(先读)

android - 在登录 Activity 中, Intent 不起作用

java - 出于有害目的在 XML 中注入(inject) Java 字节码

xml - 导入 ComplexType 时 Xsd.exe 无法生成类

android - Java Android Studio - SortableTableView 不适用于 fragment

android - 如何使用 AWS Pinpoint 通过 postman 发送推送通知

java - 由于 apache ant 上的 crashlytics 构建错误,应用程序崩溃

android - 检测图像(位图)上色点的触摸

java - 通过数组使用 XML 创建 JSP

android - 如何用圆角制作 View ?