|
A Crowd-sourced Cookbook on Writing Great Android® Apps |
|
|
|||||||
|
||||||||||
|
Chapter
7. Graphical User Interface
Contributed by
Wagied Davids 2010-12-02 12:34:49 (updated 2012-03-27 09:31:22)
In Published Edition?
Yes
|
0
Votes |
You want to customize the SlidingDrawer component to animate/transition from the top down.
Android's SlidingDrawer component's default behavior is to transition from the bottom and then move upwards on a user clicking the panel handle. To accomodate the transition from the top moving downwards, an animation is required. Use is made of the open-source org.panel package to accomplish this task.
Steps:
File: main.xml
<?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:panel="http://schemas.android.com/apk/res/org.panel" android:layout_width="fill_parent" android:layout_height="fill_parent"> <LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <org.panel.Panel android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/topPanel" android:paddingBottom="20dip" panel:position="top" panel:animationDuration="1000" panel:linearFlying="true" panel:openedHandle="@drawable/top_switcher_expanded_background" panel:closedHandle="@drawable/top_switcher_collapsed_background"> <Button android:id="@id/panelHandle" android:layout_width="fill_parent" android:layout_height="33dip" /> <LinearLayout android:id="@id/panelContent" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content"> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center" android:text="From the Top -> Down" android:textSize="16dip" android:padding="4dip" android:textStyle="bold" /> <ImageView android:src="@drawable/android_skateboard" android:layout_gravity="center" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout> </org.panel.Panel> </LinearLayout> </FrameLayout>
File: Test.java
import android.app.Activity; import android.os.Bundle; public class Test extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } }
|