利用SlidingPaneLayout实验仿QQ侧滑效果
1.效果图
2.布局文件
<?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:layout_marginTop="5dp"
android:background="#65c7fa"
android:orientation="vertical"> <TextView
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="#ffffff"
android:gravity="center"
android:text="我的功能标签"
android:textColor="#000000"
android:textSize="20sp"
android:textStyle="bold" /> <Button android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#65c7fa"
android:onClick="baidu"
android:text="百度"
android:textColor="#ffffff" /> <Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#65c7fa"
android:onClick="qq"
android:text="QQ"
android:textColor="#ffffff" /> <Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#65c7fa"
android:onClick="wangyi"
android:text="网易"
android:textColor="#ffffff" /> <Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#65c7fa"
android:onClick="sina"
android:text="新浪"
android:textColor="#ffffff" />
</LinearLayout>
</FrameLayout> <WebView
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent" /> </android.support.v4.widget.SlidingPaneLayout>
3.Java代码
import android.support.v4.widget.SlidingPaneLayout;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.LinearLayout; public class MainActivity extends AppCompatActivity { SlidingPaneLayout mSlidingPaneLayout;
View mFullLeft; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); mSlidingPaneLayout = (SlidingPaneLayout) findViewById(R.id.slidingpanelayout);
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就应完全不可见
mFullLeft.setAlpha(slideOffset);
} @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");
}
}
有借鉴别人的代码,但忘记博主啦,请见谅!!!