SlidingPaneLayout,DrawerLayout,ActionBar,NavigationView 详解 <二>SlidingPaneLayout 的 简单的使用

Metr design中所有的空间都是有厚度的。
在5.0以上,所有的控件都有自己的高度,就是z轴,在Metr design z轴越高,可以覆盖z轴低的控件。
在SlidingPaneLayout 的子控件里面增加一个属性:android:elevation="5dp",该控件就会高于其他的控件了。

注:elevation就是高度和海拔的意思,还有高尚,立视图,正视图的意思

0:布局

<?xml version="1.0" encoding="utf-8"?> <android.support.v4.widget.SlidingPaneLayout 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" android:paddingLeft="@dimen/activity_horizontal_margin"  android:paddingRight="@dimen/activity_horizontal_margin"  android:paddingTop="@dimen/activity_vertical_margin"  android:id="@+id/slidingPaneLayout"  android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">

    <LinearLayout  android:background="#090"  android:layout_width="match_parent"  android:layout_height="match_parent">
        <TextView  android:layout_width="wrap_content"  android:layout_height="wrap_content"  android:text="First LinearLayout"/>
    </LinearLayout>
    <LinearLayout  android:background="#6006"  android:layout_width="match_parent"  android:layout_height="match_parent"  android:elevation="5dp"  android:id="@+id/content">
        <TextView  android:layout_width="wrap_content"  android:layout_height="wrap_content"  android:text="Second LinearLayout"/>
    </LinearLayout>
</android.support.v4.widget.SlidingPaneLayout>

1:

package tech.androidstudio.slidingpanlayoutdemoreal;

import android.support.v4.view.ViewCompat;
import android.support.v4.widget.SlidingPaneLayout;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;

public class MainActivity extends AppCompatActivity implements SlidingPaneLayout.PanelSlideListener {

    private SlidingPaneLayout mSlidingPaneLayout;
    private LinearLayout mContent;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mSlidingPaneLayout = (SlidingPaneLayout)findViewById(R.id.slidingPaneLayout);
        mContent = (LinearLayout)findViewById(R.id.content);
        mSlidingPaneLayout.setPanelSlideListener(this);
    }

    //PanlSlidePanelSlide回调方法里面  //PanlSlidePanelSlide回调方法里面  @Override
    public void onPanelSlide(View panel, float slideOffset) {

        //获取panel的高度  int height = panel.getHeight();
        //设置缩放的中心点是右侧的中点  mContent.setPivotX(0);
        mContent.setPivotY(height/2);

        //设置缩放的等级  mContent.setScaleX(1-slideOffset);
        mContent.setScaleY(1-slideOffset);


//如果要兼容2.0的手机,2.0就是API52.1API 72.3API 9 // http://blog.csdn.net/rodulf/article/details/50743187  // ViewCompat.setPivotX(mContent, 0); // ViewCompat.setPivotX(mContent, height / 2); // ViewCompat.setScaleX(mContent, 1 - slideOffset); // ViewCompat.setScaleY(mContent, 1 - slideOffset);  }

    @Override
    public void onPanelOpened(View panel) {

    }

    @Override
    public void onPanelClosed(View panel) {

    }
}
 
 

你可能感兴趣的:(SlidingPaneLayout,DrawerLayout,ActionBar,NavigationView 详解 <二>SlidingPaneLayout 的 简单的使用)