android开发步步为营之100:开源项目SlidingUpPanelLayout简单用法

         最近需要做一个可上划面板的效果,目前github上有个开源的还是挺好用的,介绍给大家

         开源项目地址

         https://github.com/chenee/slidingUpPanel


          什么是可上划的面板,先看下效果

上划前:

上划后:



好的,开始我们的demo。

第一步、app build.gradle先引入项目依赖


compile(name: 'com.sothree.slidinguppanel-library-3.2.0', ext: 'aar')

第二步、设计页面

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:sothree="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/background"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.figo.study.activity.CameraActivity">
    <com.sothree.slidinguppanel.SlidingUpPanelLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:sothree="http://schemas.android.com/apk/res-auto"
        android:id="@+id/sliding_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="bottom"
        sothree:umanoPanelHeight="95dp"
        sothree:umanoShadowHeight="0dp">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:background="#123456"
            android:text="主页面,可以使用任何Layout"
            android:textSize="16sp" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center|top"
            android:background="#654321"
            android:text="这里是可上划的面板,可以是任何Layout,比如使用FrameLayout,将fragment嵌入进来"
            android:textSize="16sp" />
    </com.sothree.slidinguppanel.SlidingUpPanelLayout>
</LinearLayout>


第三步、编写activity

package com.figo.study.activity;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;

import com.figo.study.R;
import com.sothree.slidinguppanel.SlidingUpPanelLayout;

public class SlidinguppanelActivity extends AppCompatActivity {
    private SlidingUpPanelLayout mSlidingUpPanelLayout;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_slidinguppanel);
        initView();
    }
    //自己实现哦
    private void initView()
    {
        mSlidingUpPanelLayout = (SlidingUpPanelLayout) findViewById(R.id.sliding_layout);
        mSlidingUpPanelLayout.setPanelSlideListener(new SlidingUpPanelLayout.SimplePanelSlideListener() {
            @Override
            public void onPanelSlide(View panel, float slideOffset) {

//                AnimationUtil.setAlphaVisibility(mManagePanelMask, slideOffset);
            }

            @Override
            public void onPanelExpanded(View panel) {
//                Fragment f = getSupportFragmentManager().findFragmentById(R.id.layout_manage_container);
//
//
//                if (!(f instanceof SlidingUpPanelLayout.PanelSlideListener))
//                    return;
//
//                ((SlidingUpPanelLayout.PanelSlideListener) f).onPanelExpanded(panel);
            }

            @Override
            public void onPanelCollapsed(View panel) {
//                Fragment f = getSupportFragmentManager().findFragmentById(R.id.layout_manage_container);
//                if (!(f instanceof SlidingUpPanelLayout.PanelSlideListener))
//                    return;
//
//                ((SlidingUpPanelLayout.PanelSlideListener) f).onPanelCollapsed(panel);
            }
        });
        //在程序中加入Fragment
//        FragmentManager fragmentManager = getSupportFragmentManager();
//        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
//
//        final Fragment fragment = MyMemeFragment.getInstance();
//        fragmentTransaction.add(R.id.layout_manage_container, fragment);
//        fragmentTransaction.commit();
    }
}

         这个效果,通过viewpager应该也可以实现的。

AndroidSlidingUpPanel 是一个上拉面板, 就是向上滑动的时候往上飞出一个显示面板控件, 该库效果在 Google Music, Google Maps and Rdio等 App 中用到。 效果图: 用法:使用com.sothree.slidinguppanel.SlidingUpPanelLayout作为您的活动布局的根元素。 布局必须设置为顶部或底部。请确保它有两个元素。 第一个元素是你的主要布局。第二个元素是你的向上滑动面板布局。 主要布局应当具有的宽度和高度设置为match_parent。 滑动的布局的宽度应设置为match_parent;高度应设置为match_parent,WRAP_CONTENT或最大desireable高度。 如果您想定义高度屏幕为percetange,可将其设置为match_parent,滑动视图定义为layout_weight属性。  默认情况下,整个面板将作为拖动区域和将截获的点击和拖动事件。可以通过使用setDragView方法或umanoDragView属性限制牵引区到特定的图。 想了解更多信息,请参考示例代码:<com.sothree.slidinguppanel.SlidingUpPanelLayout     xmlns:sothree="http://schemas.android.com/apk/res-auto"     android:id="@ id/sliding_layout"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:gravity="bottom"     sothree:umanoPanelHeight="68dp"     sothree:umanoShadowHeight="4dp">     <TextView         android:layout_width="match_parent"         android:layout_height="match_parent"         android:gravity="center"         android:text="Main Content"         android:textSize="16sp" />     <TextView         android:layout_width="match_parent"         android:layout_height="match_parent"         android:gravity="center|top"         android:text="The Awesome Sliding Up Panel"         android:textSize="16sp" /> </com.sothree.slidinguppanel.SlidingUpPanelLayout>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值