Recently, a drawer-like function needs to be implemented in the project, and the component of the drawer content can implement the slide function. This function is implemented here:
First, design the layout Code. The Code is as follows:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" > <SlidingDrawer android:id="@+id/slidingDrawer1" android:layout_width="wrap_content" android:layout_height="80dp"android:layout_alignParentBottom="true" android:content="@+id/content" android:handle="@+id/handle" > <Button android:id="@+id/handle" android:layout_width="wrap_content" android:layout_height="20dp" android:text="Handle" /> <HorizontalScrollView android:id="@+id/content" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:background="@android:color/black" android:scrollbars="none" > <LinearLayout android:layout_width="wrap_content" android:layout_height="50dp" android:layout_gravity="center_vertical" android:gravity="center_vertical" android:id="@+id/content_linear" android:orientation="horizontal" > <Button android:layout_width="70dp" android:layout_height="50dp" android:layout_marginLeft="10dp" android:id="@+id/btn1" android:text="btn1" > </Button> <Button android:layout_width="70dp" android:layout_height="50dp" android:layout_marginLeft="10dp" android:text="btn2" > </Button> <Button android:layout_width="70dp" android:layout_height="50dp" android:layout_marginLeft="10dp" android:text="btn3" > </Button> <Button android:layout_width="70dp" android:layout_height="50dp" android:layout_marginLeft="10dp" android:text="btn4" > </Button> <Button android:layout_width="70dp" android:layout_height="50dp" android:layout_marginLeft="10dp" android:text="btn5" > </Button> <Button android:layout_width="70dp" android:layout_height="50dp" android:layout_marginLeft="10dp" android:text="btn5" > </Button> <Button android:layout_width="70dp" android:layout_height="50dp" android:layout_marginLeft="10dp" android:text="btn5" > </Button> <Button android:layout_width="70dp" android:layout_height="50dp" android:layout_marginLeft="10dp" android:text="btn5" > </Button> <Button android:layout_width="70dp" android:layout_height="50dp" android:layout_marginLeft="10dp" android:text="btn5" > </Button> </LinearLayout> </HorizontalScrollView> </SlidingDrawer></RelativeLayout>
The implementation code is as follows:
package com.example.test;import android.app.Activity;import android.os.Bundle;public class Test extends Activity{@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);}}
As follows:
However, there is a conflict between the sliding event and the touch event of the button. When the touch event of the button is implemented, moving the component and releasing the component cannot capture the up event. For this problem, solution in the next chapter