下拉菜单UI



我想实现一个UI,如下图所示。当点击按钮(如箭头所示)时,应该会出现下拉菜单。有可能在android中做到这一点吗?

如有任何建议,我们将不胜感激。

对于以下类型的选项使用弹出窗口:

llBack.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View arg0) {
                showPopupMenu();
            }
        });

showPopupMenu()方法为:

public void showPopupMenu() {
        LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
        View popupView = inflater.inflate(R.layout.add_file_lay,
                this.container, false);
        popupWindow = new PopupWindow(popupView, popupwidth,
                WindowManager.LayoutParams.WRAP_CONTENT, true);
        popupWindow.setOutsideTouchable(true);
        popupWindow.setBackgroundDrawable(new BitmapDrawable());
        popUpwindowinIt(popupView);
        popupWindow.showAsDropDown(findViewById(R.id.places), 0, 0);
    }

在上面的代码R.id.places中,这里是布局文件中的隐藏布局,我们想在其中显示菜单,就像菜单按钮下面一样;

这是要显示为弹出菜单的add_file_lay命名视图:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:paddingRight="5dp" >
    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="#262127" >
        <ImageView
            android:id="@+id/downarrow_afile"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:layout_marginRight="1dp" />
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp"
            android:orientation="vertical" >
            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:gravity="center_vertical"
                android:orientation="horizontal" >
                <RelativeLayout
                    android:id="@+id/gallerylay"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_marginBottom="5dp"
                    android:layout_marginTop="5dp"
                    android:layout_weight="1" >
                    <ImageView
                        android:id="@+id/gallerybtn"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_centerHorizontal="true"
                        android:src="@drawable/gal" />
                    <TextView
                        android:id="@+id/gallerytxt"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_below="@id/gallerybtn"
                        android:layout_centerHorizontal="true"
                        android:singleLine="true"
                        android:text="Gallery"
                        android:textColor="#ffffff"
                        android:textSize="12sp" />
                </RelativeLayout>
                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="#ffffff" />
                <RelativeLayout
                    android:id="@+id/photolay"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_marginBottom="5dp"
                    android:layout_marginTop="5dp"
                    android:layout_weight="1" >
                    <ImageView
                        android:id="@+id/photobtn"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_centerHorizontal="true"
                        android:src="@drawable/cam" />
                    <TextView
                        android:id="@+id/phototxt"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_below="@id/photobtn"
                        android:layout_centerHorizontal="true"
                        android:singleLine="true"
                        android:text="Take Photo"
                        android:textColor="#ffffff"
                        android:textSize="12sp" />
                </RelativeLayout>
                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="#ffffff" />
                <RelativeLayout
                    android:id="@+id/videolay"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_marginBottom="5dp"
                    android:layout_marginTop="5dp"
                    android:layout_weight="1" >
                    <ImageView
                        android:id="@+id/videobtn"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_centerHorizontal="true"
                        android:src="@drawable/video" />
                    <TextView
                        android:id="@+id/videotxt"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_below="@id/videobtn"
                        android:layout_centerHorizontal="true"
                        android:singleLine="true"
                        android:text="Video"
                        android:textColor="#ffffff"
                        android:textSize="12sp" />
                </RelativeLayout>
            </LinearLayout>
            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal" >
                <ImageView
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:background="#ffffff" />
                <ImageView
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:background="#ffffff" />
                <ImageView
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:background="#ffffff" />
            </LinearLayout>
            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:gravity="center_vertical"
                android:orientation="horizontal" >
                <RelativeLayout
                    android:id="@+id/audiolay"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_marginBottom="5dp"
                    android:layout_marginTop="5dp"
                    android:layout_weight="1" >
                    <ImageView
                        android:id="@+id/audiobtn"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_centerHorizontal="true"
                        android:src="@drawable/ausio" />
                    <TextView
                        android:id="@+id/audiotxt"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_below="@id/audiobtn"
                        android:layout_centerHorizontal="true"
                        android:layout_marginTop="1dp"
                        android:singleLine="true"
                        android:text="Audio"
                        android:textColor="#ffffff"
                        android:textSize="12sp" />
                </RelativeLayout>
                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="#ffffff" />
                <RelativeLayout
                    android:id="@+id/locationlay"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_marginBottom="5dp"
                    android:layout_marginTop="5dp"
                    android:layout_weight="1" >
                    <ImageView
                        android:id="@+id/locationbtn"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_centerHorizontal="true"
                        android:src="@drawable/location" />
                    <TextView
                        android:id="@+id/locationtxt"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_below="@id/locationbtn"
                        android:layout_centerHorizontal="true"
                        android:layout_marginTop="1dp"
                        android:singleLine="true"
                        android:text="Location"
                        android:textColor="#ffffff"
                        android:textSize="12sp" />
                </RelativeLayout>
                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="#ffffff" />
                <RelativeLayout
                    android:id="@+id/relativeLayoutAddContact"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:visibility="visible" >
                    <ImageView
                        android:id="@+id/contactbtn"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:clickable="false"
                        android:layout_centerHorizontal="true"
                        android:src="@drawable/contact" />
                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:clickable="false"
                        android:layout_below="@id/contactbtn"
                        android:layout_centerHorizontal="true"
                        android:text="Contact"
                        android:textColor="#ffffff"
                        android:textSize="12sp" />
                </RelativeLayout>
            </LinearLayout>
        </LinearLayout>
    </RelativeLayout>
</RelativeLayout>

首先使下拉菜单不可见将onclick事件添加到按钮,当它被点击时,使下拉菜单可见。这就是我的建议,因为我看不到你上传的图像

最新更新