要回答我的问题,您应该在手机中使用超级应用程序。实际上我的疑问是,在uber应用程序中,一旦我们打开应用程序,在底部我们将得到一个对话框类型的东西,例如,如果我来自班加罗尔,它将显示一个标题为" Uber Bangalore"的对话框,如果我们将刷对话框那么它正在打开其他活动如何实现相同。这是一个对话框还是其他东西。请解释一下。
答案 0 :(得分:3)
这不是一项活动。可以使用底部工作表完成。使用设计支持库。
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.在您所需的活动中拨打您的Dialog片段
BottomSheetDialogFragment bottomSheetDialogFragment = new MyBottomDialogFragment ();
bottomSheetDialogFragment.show(getSupportFragmentManager(), bottomSheetDialogFragment.getTag());
答案 1 :(得分:2)
首先澄清一些。我看到了应用程序,这个答案是根据我的理解使用您编写的功能。以下是我的观察。
你怎么能建立这个?
它不应该很难。
现在第一点,它是一个相当直接的过程,你可以找到它的博客。但是,最基本的实现可以在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;
}
}
这应该可以帮到你..
始终要打破您的问题并寻找这些零件的解决方案。如果我们能够找到正确的问题,我们有stackoverflow来指导我们完成每个问题
好运!
编辑 :@SripadRaj的回答可以很轻松地解决您的问题,我的流程很长。但是,在实施之前,请尝试了解代码背后发生的事情。