3

我正在使用 4.4 中引入的场景/过渡系统来简单地将图像视图从左侧移动到屏幕中心。所以我的第一个场景的布局要求图像不在屏幕上。我试过android:layout_marginRight了,但没有效果。这样做的正确方法是什么?

4

2 回答 2

11

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

例子:

<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>

然后在活动或片段中简单地调用该animate()函数。

    FloatingActionButton button = (FloatingActionButton)findViewById(R.id.button);
    button.animate().translationX(0);
于 2015-09-30T06:50:24.180 回答
0

正在考虑可以使图像位于已经在右侧的某物的右侧,这应该使其远离屏幕。此外,可能只是让它“消失”,然后在转换时让它出现。

于 2015-04-12T01:53:00.420 回答