I am using ObjectAnimator
to slide up a background image to reveal a listView
below. The listView
has a weight
of 0.7f
so that it will be the same proportions on all screen sizes.
Using ObjectAnimator
is it possible to then slide up my background image with that same 0.7
proportion, being the same on all screens?
Background image and 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>
Animation code:
FrameLayout mainView = (FrameLayout)findViewById(R.id.mainView);
ObjectAnimator mover = ObjectAnimator.ofFloat(mainView, "translationY", !historyShown ? -500 : 0);
mover.setDuration(300);
mover.start();
View.getLocationInWindow()
orView.getLocationOnScreen()
to determine the vertical offset of theListView
in terms of a number of pixels. That should give you all the information you need to figure out how far up you should translate the background image. Not sure when your animation runs, but if you kick it off before the view hierarchy has been fully laid out, you may want to wrap the logic inside aRunnable
and post it to the root view. – Demodulator