Nic*_*ard 5 android android-animation android-layout objectanimator
我ObjectAnimator用来滑动背景图像以显示listView下面的图像.该listView具有weight的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>
Run Code Online (Sandbox Code Playgroud)
动画代码:
FrameLayout mainView = (FrameLayout)findViewById(R.id.mainView);
ObjectAnimator mover = ObjectAnimator.ofFloat(mainView, "translationY", !historyShown ? -500 : 0);
mover.setDuration(300);
mover.start();
Run Code Online (Sandbox Code Playgroud)
实际上找到了一种更快捷,更简单的方法.由于我listView使用的weight设置0.7f始终与所有屏幕尺寸成比例.所以,我只需要获得它的高度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();
Run Code Online (Sandbox Code Playgroud)
工作得很完美!
| 归档时间: |
|
| 查看次数: |
15560 次 |
| 最近记录: |