Android drawer + slide

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.