开发者

Using different activities for different views in a ViewFlipper

开发者 https://www.devze.com 2023-01-07 04:20 出处:网络
I am developing a Music Player and I have a view flipper to control all the artist view, album view, so on and so forth. What I am doi开发者_如何转开发ng now is that I have list view in each view of t

I am developing a Music Player and I have a view flipper to control all the artist view, album view, so on and so forth. What I am doi开发者_如何转开发ng now is that I have list view in each view of the view flipper. However, I do not want to put all my codes inside one activity but rather, to have different activities for each view. Is that possible to implement?


If your goal is just to create the same user experience provided by ViewFlipper you'd be better off using overridePendingTransition(int enterAnim, int exitAnim) which has been available since API Level 5.

You'd call overridePendingTransition in whatever event was causing the activity to change. An example can be found within the Android SDK samples, but I provide one below to more fully answer your question.

First you must define your animations. Create a folder anim under res. Then define two transistions one in and one out.

in_right

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate
        android:fromXDelta="100%"
        android:toXDelta="0%"
        android:duration="600"/>
</set>

out_left

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate
        android:fromXDelta="0%"
        android:toXDelta="-100%"
        android:duration="600"/>
</set>

Then in the event which is starting the other activity you'd use these animations in your call to overridePendingTransition.

// this code snippet does not show wiring event to button
void buttonClicked() {
    startActivity(new Intent(this, HistoryListActivity_.class));
    overridePendingTransition(R.anim.in_right, R.anim.out_left);
}


However, I do not want to put all my codes inside one activity but rather, to have different activities for each view.

Please don't do this. Not only is it not possible, but the other place where this is sorta supported (TabHost), it wastes RAM and CPU.

0

精彩评论

暂无评论...
验证码 换一张
取 消