, . ( ) , . , , .
:
<RelativeLayout
android:id="@+id/drawerContainer"
android:layout_alignParentRight="true"
android:layout_width="120dp"
android:layout_height="match_parent">
<SlidingDrawer
android:id="@+id/drawer"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal"
android:handle="@+id/handle"
android:content="@+id/content">
<ImageView
android:id="@+id/handle"
android:layout_width="20dip"
android:layout_height="match_parent"
android:src="@drawable/drawer_handle />
<LinearLayout
android:id="@+id/content"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal">
<ListView
android:id="@+id/list"
android:layout_width="100dp"
android:layout_height="match_parent">
</ListView>
<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone">
</ImageView>
</LinearLayout>
</SlidingDrawer>
</RelativeLayout>
, . OnItemClickListener :
private OnItemClickListener onItemClickListener = new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (imageView.getVisibility() == View.GONE) {
ExpandViewAnimation animation = new ExpandViewAnimation(drawerContainer, ((View) drawerContainer.getParent()).getWidth());
animation.setDuration(500);
drawerContainer.setAnimation(animation);
animation.start();
imageView.setVisibility(View.VISIBLE);
}
}
};
, , . :
public class ExpandViewAnimation extends Animation {
int targetWidth;
int initialWidth;
View view;
public ExpandViewAnimation(View view, int targetWidth) {
this.view = view;
this.targetWidth = targetWidth;
initialWidth = view.getWidth();
}
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
int newWidth = initialWidth + (int) ((targetWidth - initialWidth) * interpolatedTime);
LayoutParams lp = new LayoutParams((LayoutParams) view.getLayoutParams());
lp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
view.setLayoutParams(lp);
view.getLayoutParams().width = newWidth;
view.requestLayout();
if (newWidth == targetWidth) {
LayoutParams matchParentParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
view.setLayoutParams(matchParentParams);
view.clearAnimation();
}
}
@Override
public void initialize(int width, int height, int parentWidth, int parentHeight) {
super.initialize(width, height, parentWidth, parentHeight);
}
@Override
public boolean willChangeBounds() {
return true;
}
}
, , , ( ) onDrawerClose:
private OnDrawerCloseListener onDrawerCloseListener = new OnDrawerCloseListener() {
@Override
public void onDrawerClosed() {
imageView.setVisibility(View.GONE);
imageView.setImageDrawable(null);
drawerContainer.setLayoutParams(initialLayoutParams);
}
};
, , onTouchListener.
: , , . , .