gpt4 book ai didi

Android ObjectAnimator 动画 translationY 在所有屏幕尺寸上的比例相同

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:21:32 24 4
gpt4 key购买 nike

我正在使用 ObjectAnimator 向上滑动背景图像以显示下面的 listViewlistView权重0.7f,因此它在所有屏幕尺寸上的比例都相同。

使用 ObjectAnimator 是否可以将我的背景图像以相同的 0.7 比例向上滑动,在所有屏幕上都一样?

背景图片和listView:

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1" >

<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.3" >
</LinearLayout>

<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.7"
android:background="#303030"
android:divider="#555555"
android:dividerHeight="1dp" >

</ListView>

</LinearLayout>

动画代码:

FrameLayout mainView = (FrameLayout)findViewById(R.id.mainView);
ObjectAnimator mover = ObjectAnimator.ofFloat(mainView, "translationY", !historyShown ? -500 : 0);
mover.setDuration(300);
mover.start();

最佳答案

实际上想出了一个更快更简单的方法。由于我的 listView 使用 0.7fweight 设置,它始终与所有屏幕尺寸成比例。所以,我只需要获取 listView 的高度并在我的 ObjectAnimator 中使用它:

 // Figure out where listView is
int listViewHeight = list.getHeight();

FrameLayout mainView = (FrameLayout)findViewById(R.id.mainView);
ObjectAnimator mover = ObjectAnimator.ofFloat(mainView, "translationY", !historyShown ? -listViewHeight : 0);
mover.setDuration(300);
mover.start();

完美运行!

关于Android ObjectAnimator 动画 translationY 在所有屏幕尺寸上的比例相同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18950808/

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