刷卡正在打开另一个活动如何实现相同的

问题描述:

回答我的问题,你应该在你的手机超级应用程序。其实我的疑问是,在超级应用程序中,一旦我们打开应用程序,在底部我们会得到一个对话类的东西,例如,如果我来自班加罗尔,它会显示一个对话,标题如“Uber Bangalore”,如果我们将对话,然后它打开其他活动如何实现相同。这是一个对话框或其他东西。请解释我。刷卡正在打开另一个活动如何实现相同的

+0

我在找这个,谢谢你的排队 –

这不能是一项活动。它可以使用底部表单完成。使用设计支持库。

compile 'com.android.support:design:24.1.1' 

1.创建一个类和它延伸BottomSheetDialogFragment。创建您想要的布局并使用setupDialog()方法对其进行充气。

public class MyBottomDialogFragment extends BottomSheetDialogFragment { 

    @Override 
    public void setupDialog(final Dialog dialog, int style) { 
     super.setupDialog(dialog, style); 
     View contentView = View.inflate(getContext(), R.layout.fragment_bottomsheet3, null); 
     dialog.setContentView(contentView); 
    } 
} 

2.Call你在你需要的活动对话框片的第一

BottomSheetDialogFragment bottomSheetDialogFragment = new MyBottomDialogFragment(); 
bottomSheetDialogFragment.show(getSupportFragmentManager(), bottomSheetDialogFragment.getTag()); 

很少澄清。我看到了应用程序,这个答案是根据我对使用你写的功能后的理解。以下是我的观察。

  1. 它不是打开一个Activity,而是打开一个片段。
  2. 它不是对话框,而是片段可见的部分
  3. 当您拉起时,片段会完全加载到活动上。

你怎么建立这个?

它不应该很难。

  • 在MapsActivity布局文件中使用FrameLayout。这个FrameLayout将成为这个片段的容器。
  • 在活动中加载yout片段,但它应该沿着屏幕向下移动,以便只有片段的10%可见。
  • 打开向上滑动,将其完全加载到屏幕上。

现在第一点,它是相当直接的过程,你可以找到博客。但是最基本的实现可以在Official Google documentation

对于第二部分被发现,我没有太多的想法,我从来没有实施这样的事情,但这些链接应该是有帮助的:

Moving a fragment partially off screen

https://github.com/StevenRudenko/ActionsContentView

对于第三部分,您必须检测并确定用户滑动的方向。我可以提供一类:

所有学分到:How to detect swipe direction between left/right and up/down

import android.view.GestureDetector; 
import android.view.MotionEvent; 

public class OnSwipeListener extends GestureDetector.SimpleOnGestureListener 
{ 

@Override 
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { 

    // Grab two events located on the plane at e1=(x1, y1) and e2=(x2, y2) 
    // Let e1 be the initial event 
    // e2 can be located at 4 different positions, consider the following diagram 
    // (Assume that lines are separated by 90 degrees.) 
    // 
    // 
    //   \ A/
    //   \/
    //  D e1 B 
    //  /\ 
    //  /C \ 
    // 
    // So if (x2,y2) falls in region: 
    // A => it's an UP swipe 
    // B => it's a RIGHT swipe 
    // C => it's a DOWN swipe 
    // D => it's a LEFT swipe 
    // 

    float x1 = e1.getX(); 
    float y1 = e1.getY(); 

    float x2 = e2.getX(); 
    float y2 = e2.getY(); 

    Direction direction = getDirection(x1,y1,x2,y2); 
    return onSwipe(direction); 
} 

/** Override this method. The Direction enum will tell you how the user swiped. */ 
public boolean onSwipe(Direction direction){ 
    return false; 
} 

/** 
* Given two points in the plane p1=(x1, x2) and p2=(y1, y1), this method 
* returns the direction that an arrow pointing from p1 to p2 would have. 
* @param x1 the x position of the first point 
* @param y1 the y position of the first point 
* @param x2 the x position of the second point 
* @param y2 the y position of the second point 
* @return the direction 
*/ 
public Direction getDirection(float x1, float y1, float x2, float y2){ 
    double angle = getAngle(x1, y1, x2, y2); 
    return Direction.get(angle); 
} 

/** 
* 
* Finds the angle between two points in the plane (x1,y1) and (x2, y2) 
* The angle is measured with 0/360 being the X-axis to the right, angles 
* increase counter clockwise. 
* 
* @param x1 the x position of the first point 
* @param y1 the y position of the first point 
* @param x2 the x position of the second point 
* @param y2 the y position of the second point 
* @return the angle between two points 
*/ 
public double getAngle(float x1, float y1, float x2, float y2) { 

    double rad = Math.atan2(y1-y2,x2-x1) + Math.PI; 
    return (rad*180/Math.PI + 180)%360; 
} 


public enum Direction{ 
    up, 
    down, 
    left, 
    right; 

    /** 
    * Returns a direction given an angle. 
    * Directions are defined as follows: 
    * 
    * Up: [45, 135] 
    * Right: [0,45] and [315, 360] 
    * Down: [225, 315] 
    * Left: [135, 225] 
    * 
    * @param angle an angle from 0 to 360 - e 
    * @return the direction of an angle 
    */ 
    public static Direction get(double angle){ 
     if(inRange(angle, 45, 135)){ 
      return Direction.up; 
     } 
     else if(inRange(angle, 0,45) || inRange(angle, 315, 360)){ 
      return Direction.right; 
     } 
     else if(inRange(angle, 225, 315)){ 
      return Direction.down; 
     } 
     else{ 
      return Direction.left; 
     } 

    } 

    /** 
    * @param angle an angle 
    * @param init the initial bound 
    * @param end the final bound 
    * @return returns true if the given angle is in the interval [init, end). 
    */ 
    private static boolean inRange(double angle, float init, float end){ 
     return (angle >= init) && (angle < end); 
    } 
} 
} 

现在你可以用它实现View.OntouchListener。这个例子

public class YOURCLASS implements View.OnTouchListener { 
    gestureDetector=new GestureDetector(getActivity(),new OnSwipeListener(){ 

     @Override 
     public boolean onSwipe(Direction direction) { 
      if (direction==Direction.up){ 

       //LOAD FRAGMENT FULLY 

      } 
      return true; 
     } 


    }); 

    @Override 
public boolean onTouch(View v, MotionEvent event) { 
    gestureDetector.onTouchEvent(event); 
    return true; 
} 
} 

这应该做的伎俩你..

它始终是打破你的问题,并寻找到那些个别部分的解决方案。如果我们能够找到正确的问题,我们有计算器来指导我们解决所有问题

好运!

编辑:由@SripadRaj答案真的可以轻松解决你的问题,我的过程是相当长的。但是在实现之前,试着了解代码背后发生了什么。

+0

谢谢大家。 – shree

+0

谢谢大家。 – shree

+0

很好的解释:)谢谢。 –