码迷,mamicode.com
首页 > 移动开发 > 详细

Android android.support.v4.widget.SlidingPaneLayout 侧滑示例

时间:2015-06-12 11:47:49      阅读:235      评论:0      收藏:0      [点我收藏+]

标签:android   slidingpanelayout   

技术分享

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


Android android.support.v4.widget.SlidingPaneLayout 侧滑示例

标签:android   slidingpanelayout   

原文地址:http://blog.csdn.net/jjwwmlp456/article/details/46468603

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!