Android 如何实现一个小弹出按钮上的一些图像点击

Android 如何实现一个小弹出按钮上的一些图像点击,android,dialog,popup,Android,Dialog,Popup,当用户点击三个蓝点按钮时,我想要一个这样的弹出窗口。如何在android中实现这种类型的弹出视图。任何库都可用。?您应该试试 弹出菜单在锚定到视图的模式弹出窗口中显示菜单。如果有空间,弹出窗口将显示在锚定视图下方,如果没有空间,弹出窗口将显示在锚定视图上方。如果IME是可见的,弹出窗口将不会重叠,直到它被触摸。触摸弹出窗口外部会将其关闭 这是一个很好的例子。你可以使用这个库来实现你的目标看看这个 如果您想创建自定义,请使用以下类 创建一个这样的自定义类 public class To

当用户点击三个蓝点按钮时,我想要一个这样的弹出窗口。如何在android中实现这种类型的弹出视图。任何库都可用。?

您应该试试

弹出菜单在锚定到视图的模式弹出窗口中显示菜单。如果有空间,弹出窗口将显示在锚定视图下方,如果没有空间,弹出窗口将显示在锚定视图上方。如果IME是可见的,弹出窗口将不会重叠,直到它被触摸。触摸弹出窗口外部会将其关闭


这是一个很好的例子。

你可以使用这个库来实现你的目标看看这个

如果您想创建自定义,请使用以下类 创建一个这样的自定义类

public class TooltipWindow {

private static final int MSG_DISMISS_TOOLTIP = 100;
private Context ctx;
private PopupWindow tipWindow;
private View contentView;
private LayoutInflater inflater;

public TooltipWindow(Context ctx) {
    this.ctx = ctx;
    tipWindow = new PopupWindow(ctx);

    inflater = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    contentView = inflater.inflate(R.layout.tooltip_layout, null);
}

void showToolTip(View anchor) {

    tipWindow.setHeight(LayoutParams.WRAP_CONTENT);
    tipWindow.setWidth(LayoutParams.WRAP_CONTENT);

    tipWindow.setOutsideTouchable(true);
    tipWindow.setTouchable(true);
    tipWindow.setFocusable(true);
    tipWindow.setBackgroundDrawable(new BitmapDrawable());

    tipWindow.setContentView(contentView);

    int screen_pos[] = new int[2];
    // Get location of anchor view on screen
    anchor.getLocationOnScreen(screen_pos);

    // Get rect for anchor view
    Rect anchor_rect = new Rect(screen_pos[0], screen_pos[1], screen_pos[0]
            + anchor.getWidth(), screen_pos[1] + anchor.getHeight());

    // Call view measure to calculate how big your view should be.
    contentView.measure(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT);

    int contentViewHeight = contentView.getMeasuredHeight();
    int contentViewWidth = contentView.getMeasuredWidth();
    // In this case , i dont need much calculation for x and y position of
    // tooltip
    // For cases if anchor is near screen border, you need to take care of
    // direction as well
    // to show left, right, above or below of anchor view
    int position_x = anchor_rect.centerX() - (contentViewWidth / 2);
    int position_y = anchor_rect.bottom - (anchor_rect.height() / 2);

    tipWindow.showAtLocation(anchor, Gravity.NO_GRAVITY, position_x, position_y);

    // send message to handler to dismiss tipWindow after X milliseconds
    handler.sendEmptyMessageDelayed(MSG_DISMISS_TOOLTIP, 4000);
}

boolean isTooltipShown() {
    if (tipWindow != null && tipWindow.isShowing())
        return true;
    return false;
}

void dismissTooltip() {
    if (tipWindow != null && tipWindow.isShowing())
        tipWindow.dismiss();
}

Handler handler = new Handler() {
    public void handleMessage(android.os.Message msg) {
        switch (msg.what) {
            case MSG_DISMISS_TOOLTIP:
                if (tipWindow != null && tipWindow.isShowing())
                    tipWindow.dismiss();
                break;
        }
    }

    ;
};

}
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
    <rotate
        android:fromDegrees="45"
        android:pivotX="-50%"
        android:pivotY="80%"
        android:toDegrees="45" >
        <shape android:shape="rectangle" >
            <solid android:color="#000000" >
            </solid>

            <stroke
                android:width="2dp"
                android:color="#000000" />
        </shape>
    </rotate>
</item>
现在,为这类自定义布局创建工具提示\u布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >

<ImageView
    android:id="@+id/tooltip_nav_up"
    android:layout_width="25dp"
    android:layout_height="25dp"
    android:layout_gravity="center"
    android:background="@drawable/nav_up" />

<TextView
    android:id="@+id/tooltip_text"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/tooltip_bg"
    android:gravity="center"
    android:padding="10dp"
    android:text="Tooltip using PopupWindow:)"
    android:textColor="@android:color/white"
    android:textSize="20dp"
    android:textStyle="bold" />
    </LinearLayout>
如果有任何疑问,请询问我

使用:


非常感谢。那个worked@Saneesh最受欢迎的享受你救了我,伙计。谢谢你的帮助。Khub Khub abhar.@realpranav很高兴能帮助你
TooltipWindow tipWindow = new TooltipWindow(MainActivity.this);
 @Override
public void onClick(View v) {
    if (!tipWindow.isTooltipShown())
        tipWindow.showToolTip(v);
}
  View popupView =LayoutInflater.from(context).inflate(R.layout.urxml,null); 
//Design layout of popup view and inflate it here


popupView.findViewById(R.id.whatsapp).setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v) {
                //Handle onClicks here
            }});
// Other onClickListeners

    PopupWindow popupWindow = new PopupWindow(
                    popupView,
                    RelativeLayout.LayoutParams.WRAP_CONTENT,
                    RelativeLayout.LayoutParams.WRAP_CONTENT);

            popupWindow.setAnimationStyle(R.style.UrAnimation);
            popupWindow.showAtLocation(threeDotsView, Gravity.CENTER, x, y); //Position of view on the screen
            popupWindow.setOutsideTouchable(true);
            popupWindow.setFocusable(true);
            popupWindow.setBackgroundDrawable(new BitmapDrawable());