最近需要做一个可上划面板的效果,目前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>
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应该也可以实现的。