如何实现umano / AndroidSlidingUpPanel LIB [英] how to implement umano/AndroidSlidingUpPanel lib
问题描述
我的应用程序有一个地图片段。并点击标记,同比动画的幻灯片,从底部到屏幕的一半。它滑下再次单击标记。
My App has a map fragment . And on clicking marker , an slide up animation shows from bottom to half of screen . And it slide down on clicking marker again .
我想:滑动菜单应该可以点击或拖动山墙,使其
可以移动到屏幕的顶部。更清晰,我的意思是无论是在
点击或拖动这张幻灯片菜单是屏幕上的一半,
应到屏幕的上方。
I want : Slide up menu should be clickable or drag gable so that it can move to top of screen . to be more clear , i mean either on clicking or dragging this slide up menu which is on half of screen , should go to top of screen .
到目前为止,我完成:在点击标记,请拨打向上滑动动画屏幕的一半。 :
So far i done : On clicking marker, call the slide up animation to half of screen. :
动画code:slide_up.xml
Animation code : slide_up.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<objectAnimator
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:propertyName="yFraction"
android:valueType="floatType"
android:valueFrom="1.0"
android:valueTo="0.58"
android:duration="@android:integer/config_mediumAnimTime"/>
<objectAnimator
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:propertyName="alpha"
android:valueType="floatType"
android:valueFrom="0.58"
android:valueTo="1.0"
android:duration="@android:integer/config_mediumAnimTime"/>
</set>
slide_down.xml
slide_down.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<objectAnimator
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:propertyName="yFraction"
android:valueType="floatType"
android:valueFrom="0.58"
android:valueTo="1.0"
android:duration="@android:integer/config_mediumAnimTime"/>
<objectAnimator
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:propertyName="alpha"
android:valueType="floatType"
android:valueFrom="1"
android:valueTo="0"
android:duration="@android:integer/config_mediumAnimTime"/>
</set>
在code,其中呼吁标记点击该动画的活动:
The code in Activity which calling this Animation on Marker click :
public void toggleList() {
Fragment f = getFragmentManager().findFragmentByTag(LIST_FRAGMENT_TAG);
if (f != null) {
getFragmentManager().popBackStack();
} else {
getFragmentManager()
.beginTransaction()
.setCustomAnimations(R.anim.slide_up,
R.anim.slide_down,
R.anim.slide_up,
R.anim.slide_down)
.add(R.id.list_fragment_container, BaseMapSlidingFragment
.instantiate(this, BaseMapSlidingFragment.class.getName()),
LIST_FRAGMENT_TAG
)
.addToBackStack(null).commit();
googleMap.getUiSettings().setAllGesturesEnabled(false);
if(animCheck == false){
animCheck = true;
}else
{
animCheck= false;
}
}}
menu_Sliding.up.xml
<?xml version="1.0" encoding="utf-8"?>
<com.trickyandroid.fragmenttranslate.app.view.SlidingRelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="200dp"
android:background="#7c7c7c">
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</com.trickyandroid.fragmenttranslate.app.view.SlidingRelativeLayout>
Custom_View:
**package com.trickyandroid.fragmenttranslate.app.view;
import android.content.Context;
import android.util.AttributeSet;
import android.view.ViewTreeObserver;
import android.widget.RelativeLayout;
/**
* Created by paveld on 4/13/14.
*/
public class SlidingRelativeLayout extends RelativeLayout {
private float yFraction = 0;
public SlidingRelativeLayout(Context context) {
super(context);
}
public SlidingRelativeLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
public SlidingRelativeLayout(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
private ViewTreeObserver.OnPreDrawListener preDrawListener = null;
public void setYFraction(float fraction) {
this.yFraction = fraction;
if (getHeight() == 0) {
if (preDrawListener == null) {
preDrawListener = new ViewTreeObserver.OnPreDrawListener() {
@Override
public boolean onPreDraw() {
getViewTreeObserver().removeOnPreDrawListener(preDrawListener);
setYFraction(yFraction);
return true;
}
};
getViewTreeObserver().addOnPreDrawListener(preDrawListener);
}
return;
}
float translationY = getHeight() * fraction;
setTranslationY(translationY);
}
public float getYFraction() {
return this.yFraction;
}
}**
现在,如何得到这个菜单,屏幕上方点击上向上滑动菜单
这是在屏幕的一半?的
Now how to get this menu to top of screen on clicking slide up menu which is on the half of screen ?
推荐答案
我建议你使用 AndroidSlidingUpPanel 库中,可以找到的此处。没有一点为你再写同样的事情。
I suggest you to use AndroidSlidingUpPanel library, that can be found here. There is no point for you to write the same thing again.
它有什么需要等等。这是很容易使用和修改(我使用它在我的项目)。
It has what you need and much more. It is easy to use and modify (I am using it in my project).
如何使用
- 包含
com.sothree.slidinguppanel.SlidingUpPanelLayout
为您的活动布局的根元素。 - 布局必须重设置为顶部或底部。
- 确保它有两个孩子。第一个孩子是你的主要布局。第二个孩子是你的向上滑动面板布局。
- 主要布局应具备的宽度和高度设置为
match_parent
。 - 滑动布局应设置宽度为
match_parent
和高度设置为match_parent
,WRAP_CONTENT
或最大desireable高度。 - 默认情况下,整个面板将作为一个阻力区域,将拦截点击和拖动事件。您可以通过使用
setDragView
方法限制牵引区域特定的视图或umanoDragView
属性。
- Include
com.sothree.slidinguppanel.SlidingUpPanelLayout
as the root element in your activity layout. - The layout must have gravity set to either top or bottom.
- Make sure that it has two children. The first child is your main layout. The second child is your layout for the sliding up panel.
- The main layout should have the width and the height set to
match_parent
. - The sliding layout should have the width set to
match_parent
and the height set to eithermatch_parent
,wrap_content
or the max desireable height. - By default, the whole panel will act as a drag region and will intercept clicks and drag events. You can restrict the drag area to a specific view by using the
setDragView
method orumanoDragView
attribute.
这篇关于如何实现umano / AndroidSlidingUpPanel LIB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!