Android android.support.v4.widget.SlidingPaneLayout 側滑樣本,android側滑菜單

來源:互聯網
上載者:User

Android android.support.v4.widget.SlidingPaneLayout 側滑樣本,android側滑菜單


SlidingPaneLayout 用於水平滾動兩個view, 第一個view是左側邊,第二個view是content view


slding_pane_layout.xml

<?xml version="1.0" encoding="utf-8"?><android.support.v4.widget.SlidingPaneLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:id="@+id/slidingpanelayout"    android:layout_width="match_parent"    android:layout_height="match_parent">    <FrameLayout        android:layout_width="200dp"        android:layout_height="match_parent">        <LinearLayout            android:id="@+id/full_left"            android:layout_width="match_parent"            android:layout_height="match_parent"            android:background="#acd"            android:gravity="center"            android:orientation="vertical">            <Button                android:layout_width="match_parent"                android:layout_height="wrap_content"                android:onClick="baidu"                android:text="百度"                android:textColor="#aaff00" />            <Button                android:layout_width="match_parent"                android:layout_height="wrap_content"                android:onClick="qq"                android:text="QQ"                android:textColor="#aaff00" />            <Button                android:layout_width="match_parent"                android:layout_height="wrap_content"                android:onClick="wangyi"                android:text="網易"                android:textColor="#aaff00" />            <Button                android:layout_width="match_parent"                android:layout_height="wrap_content"                android:onClick="sina"                android:text="新浪"                android:textColor="#aaff00" />        </LinearLayout>        <TextView            android:id="@+id/small_left"            android:layout_width="80dp"            android:layout_height="match_parent"            android:background="#acd"            android:text="我是側邊的收縮狀態. 右滑展開側邊欄,書籤。"            android:textColor="#ff00" />    </FrameLayout>    <WebView        android:id="@+id/webview"        android:layout_width="match_parent"        android:layout_height="match_parent"        android:layout_marginLeft="80dp" /></android.support.v4.widget.SlidingPaneLayout>

/** * author : stone * email  : aa86799@163.com * time   : 15/6/11 15 05 */public class SlidingPaneLayoutActi extends Activity {    SlidingPaneLayout mSlidingPaneLayout;    View mSmallLeft;    View mFullLeft;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.slding_pane_layout);        mSlidingPaneLayout = (SlidingPaneLayout) findViewById(R.id.slidingpanelayout);        mSmallLeft = findViewById(R.id.small_left);        mFullLeft = findViewById(R.id.full_left);        mFullLeft.setAlpha(0);//預設 full側欄隱藏 顯示最小-預覽式的側欄        mWebView = (WebView) findViewById(R.id.webview);        WebSettings settings = mWebView.getSettings();        settings.setJavaScriptEnabled(true);        WebViewClient client = new WebViewClient();        mWebView.setWebViewClient(client);        mSlidingPaneLayout.setPanelSlideListener(new SlidingPaneLayout.PanelSlideListener() {            @Override            public void onPanelSlide(View panel, float slideOffset) {                //slideOffset: close left->open left    from 0-1                System.out.println("slide" + slideOffset);                //view.setalpha(0~1)                //full完全顯示時small就應完全不可見                mSmallLeft.setAlpha(1 - slideOffset);                mFullLeft.setAlpha(slideOffset);                mSmallLeft.setVisibility(mSlidingPaneLayout.isOpen() ? View.GONE : View.VISIBLE);            }            @Override            public void onPanelOpened(View panel) {                System.out.println("opened");            }            @Override            public void onPanelClosed(View panel) {                System.out.println("closed");            }        });    }    WebView mWebView;    public void baidu(View view) {        mWebView.loadUrl("http://www.baidu.com");    }    public void qq(View view) {        mWebView.loadUrl("http://www.qq.com");    }    public void wangyi(View view) {        mWebView.loadUrl("http://www.163.com");    }    public void sina(View view) {        mWebView.loadUrl("http://www.sina.com");    }}


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.