[水平弹出菜单?

问题描述 投票:0回答:3

[我试图单击Popupmenu时显示共享按钮,并显示三个水平选项facebooktwittergoogle+

我一直搜索了一段时间,但直到现在我什么都没得到。

是否可以创建水平或均匀网格PopupMenu?是否可以在RecyclerView中使用PopupMenu

android grid popupmenu horizontallist
3个回答
0
投票

您可以使用自定义布局的PopupMenu而不是DialogFragment


0
投票

在这种情况下,您可以使用PopupWindow。您可以使用ListView在每行中显示项目。显示PopupWindow的示例代码:

 public PopupWindow popupWindowsort() {

    // initialize a pop up window type
    popupWindow = new PopupWindow(this);

    ArrayList<String> sortList = new ArrayList<String>();
    sortList.add("Google+");
    sortList.add("Facebook");
    sortList.add("Twitter");

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
            android.R.layout.simple_dropdown_item_1line, sortList);
    // the drop down list is a list view
    ListView listViewSort = new ListView(this);

    // set our adapter and pass our pop up window contents
    listViewSort.setAdapter(adapter);

    // set on item selected
    listViewSort.setOnItemClickListener(onItemClickListener());

    // some other visual settings for popup window
    popupWindow.setFocusable(true);
    popupWindow.setWidth(250);
    //popupWindow.setBackgroundDrawable(getResources().getDrawable(R.drawable.white));
    popupWindow.setHeight(WindowManager.LayoutParams.WRAP_CONTENT);

    // set the list view as pop up window content
    popupWindow.setContentView(listViewSort);

    return popupWindow;
}

访问我的帖子以获取更多详细信息:http://www.devexchanges.info/2015/02/android-popupwindow-show-as-dropdown.html。希望有帮助!


0
投票

创建具有内部水平布局的基本布局XML。

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

将布局分配给PopupMenu,然后使用内部布局。

// PopupMenu accepts ViewGroup, so cast the inflated layout view
// Replace ROOT_VIEW_HERE with the parent view of the PopupMenu
LinearLayout popupWindow = (LinearLayout) LayoutInflater.from(this).inflate(R.layout.popup_window, ROOT_VIEW_HERE);
PopupMenu popupMenu = new PopupMenu(this, popupWindow);
LinearLayout innerView = popupWindow.findViewById(R.id.popup_horizontal);

真的就是这么简单。

© www.soinside.com 2019 - 2024. All rights reserved.