Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/230.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法理解何时在Android中使用getLeft、setLeft等?_Android_Android Layout_Coordinates_Css Position - Fatal编程技术网

无法理解何时在Android中使用getLeft、setLeft等?

无法理解何时在Android中使用getLeft、setLeft等?,android,android-layout,coordinates,css-position,Android,Android Layout,Coordinates,Css Position,问题是,我正在为布局中的一些视图设置动画,然后尝试在动画之后获取该视图的左变量和右变量,但返回值始终是未设置动画时的初始值 我使用的属性动画如下所示: 例如,将中间帧移动其宽度的4/3,并通过播放其alpha使其再次出现在屏幕上 middleFrame.animate().translationXBy(4*(middleFrame.getWidth())/3).alpha(1.0f); 然而,在动画之后,我应该能够得到中间帧的左右变化值,但当我尝试这样做时,正如我之前所说,它会给我以前的值 我

问题是,我正在为布局中的一些视图设置动画,然后尝试在动画之后获取该视图的左变量和右变量,但返回值始终是未设置动画时的初始值

我使用的属性动画如下所示:

例如,将中间帧移动其宽度的4/3,并通过播放其alpha使其再次出现在屏幕上

middleFrame.animate().translationXBy(4*(middleFrame.getWidth())/3).alpha(1.0f);
然而,在动画之后,我应该能够得到中间帧的左右变化值,但当我尝试这样做时,正如我之前所说,它会给我以前的值

我已经检查了这个问题和罗曼盖伊的答案

但是,我不太明白什么时候可以使用getLeft/Right或getLocationOnScreen等方法

我已经尝试过getLocationOnScreen或getLocationInWindow,但它们返回相同的结果


提前感谢。

我也不明白为什么getLocationOnScreen和getLocationInWindow返回相同的值

getLeft/Right/Top/Bottom返回以像素为单位查看父对象的偏移量。 您不能将其用于动画,因为此信息是静态的,仅提供有关布局的信息

简单的例子:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
        <TextView  
            android:layout_width="wrap_content" 
            android:layout_height="fill_parent" 
            android:text="@string/hello" />
        <TextView  
            android:layout_width="wrap_content" 
            android:layout_height="fill_parent" 
            android:text="@string/hello" />
</LinearLayout>
如果使用此布局并设置第一个文本视图的动画并向右平移,则会溢出第二个文本视图,而不是将其推到右侧。因此,基本上,第一个文本视图仍然处于其原来的位置,即getLeft/Right/Top/Bottom相同的值,但在内部被移动到了另一个位置


直截了当地说:动画只是一种视觉效果,与布局定位无关。

我认为属性动画也会影响真实对象的属性,因此布局定位也会受到影响。嗯,我是这样想的。但是如果我错了,也许有人会纠正我。例如,旋转将如何影响布局?!