您的位置:首页 > 移动开发 > Android开发

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

2015-06-12 10:37 483 查看


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");
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: