Reputation: 2135
I want to show the layout on Pull of ActionBar/ToolBar items. This layout has to overlay ActionBar/ToolBar, in otherwords this layout has to visible on top of ActionBar/Toolbar.
This requirement is similar to Android's default Notification Drawer.
I have a ToolBar and a item on it. If I pull that item, a new layout has to come from Top with fixed height and this layout can be closed by tapping on that ToolBar item with pull effect.
I tried Umano's SlidingPanel couldn't succeed.
And I used DialogPlus library. I get closer to my requirement. Using DialogPlus it can be achieved on click of ToolBar item but pull effect is missing.
How can I show/hide a layout using pull effect?
Upvotes: 1
Views: 431
Reputation: 664
To do things in response to a gesture implement gestureListener. For this case you can create an anonymous inner class or you can straight away implement the SimpleGestureListener and in onFling method you can code your logic for change of layout.
public class MainActivity extends Activity implements
GestureDetector.OnGestureListener,
GestureDetector.OnDoubleTapListener{
private GestureDetectorCompat mDetector;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
...
//other unimplemented methods..
@Override
public boolean onFling(MotionEvent event1, MotionEvent event2,
float velocityX, float velocityY) {
//logic for layout change
return true;
}
}
Upvotes: 0
Reputation: 1248
here is a simple xml file
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:animateLayoutChanges="true"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#0061C2"
android:minHeight="?attr/actionBarSize"
app:popupTheme="@style/Theme.AppCompat.Light.DarkActionBar"
app:theme="@style/Toolbar"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<RelativeLayout
android:id="@+id/myLayout"
android:layout_width="fill_parent"
android:layout_height="200dp"
android:background="#ffff7100"
android:visibility="gone">
</RelativeLayout>
</RelativeLayout>
The toolbar is behinf "myLayout" , so if "myLayout" is visible it will hide the toolbar in your java , when clicking on that item
(findViewById(R.id.myLayout).setVisibility(View.VISIBLE);
and a layout will be displayed, you will get an animation because i'm using
android:animateLayoutChanges="true"
add the same item at the bottom of myLayout and add this as its onClickListener
(findViewById(R.id.myLayout).setVisibility(View.GONE);
You can do this using toolbar
Upvotes: 1