android抽屜+滑動

來源:互聯網
上載者:User

最近在項目裡面需要做一個類似抽屜的功能,同時抽屜的內容的組件能夠實現滑動功能,這裡實現這個功能:

首先設計布局代碼,代碼如下:

<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>

實現代碼如下:

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);}}

 

如下:

 

 

但是這裡有一個問題就是滑動事件與按鈕的Touch事件衝突,當實現按鈕的touch事件的時候,移動組件,鬆開組件無法捕獲其up事件,對於這個問題,在下一章解決

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.