gpt4 book ai didi

android - 如何在 Android 布局中将 View 定位在屏幕外

转载 作者:太空宇宙 更新时间:2023-11-03 11:56:36 38 4
gpt4 key购买 nike

我正在使用 4.4 中引入的场景/过渡系统来简单地将 ImageView 从左侧移动到屏幕中央。所以我的第一个场景的布局要求图像在屏幕外。我尝试了 android:layout_marginRight 但没有效果。执行此操作的正确方法是什么?

最佳答案

使用具有负值的属性 translationXtranslationY。此属性设置此 View 相对于其左侧/顶部位置的水平/垂直位置。 您不会在预览中看到屏幕外的 View 。运行您的应用程序并且必须隐藏 View 。

例子:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.design.widget.FloatingActionButton
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|start"
android:layout_margin="16dp"
android:translationX="-72dp"/>

</FrameLayout>

然后在 Activity 或 fragment 中简单地调用 animate() 函数。

    FloatingActionButton button = (FloatingActionButton)findViewById(R.id.button);
button.animate().translationX(0);

关于android - 如何在 Android 布局中将 View 定位在屏幕外,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29585046/

38 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com