【问题标题】:popup window instead of popup menu弹出窗口而不是弹出菜单
【发布时间】:2014-02-17 05:41:26
【问题描述】:

我想在单击图像(菜单)时在我的应用程序中显示popup window 但我的问题是我想根据我的heightwidth 显示它而不是默认值,

这是我的代码,

ivmainmenu.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub

            LayoutInflater layoutInflater 
             = (LayoutInflater)getBaseContext()
              .getSystemService(LAYOUT_INFLATER_SERVICE);  
            View popupView = layoutInflater.inflate(R.layout.popupwindow, null);  
                     final PopupWindow popupWindow = new PopupWindow();  

                     popupWindow.showAsDropDown(ivmainmenu, 50, -30);

           }});

这是我的 xml 文件,我想在我的应用程序中显示这个 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="145dp"
        android:layout_marginTop="70dp"
        android:orientation="vertical"
        android:background="#000000">

        <LinearLayout 
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:layout_marginTop="10dp"
            android:layout_marginLeft="30dp"
            android:layout_marginRight="30dp">

            <TextView 
                android:id="@+id/tvpopupwork"
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:text="OUR WORK"
                android:textSize="17dp"
                android:layout_marginLeft="10dp"/>
            <LinearLayout 
                android:layout_height="wrap_content"
                android:layout_width="match_parent"
                android:gravity="right|center">

                <TextView
                    android:id="@+id/tvwork1"
                    android:layout_width="wrap_content"
                    android:layout_height="20dp"
                    android:text="»"
                    android:textSize="20dp" 
                    android:layout_gravity="center"/>

            </LinearLayout>
        </LinearLayout>

         <LinearLayout 
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:layout_marginTop="10dp"
            android:layout_marginLeft="30dp"
            android:layout_marginRight="30dp">

            <TextView 
                android:id="@+id/tvpopupabout"
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:text="SERVICES"
                android:textSize="17dp"
                android:layout_marginLeft="10dp"/>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="right|center" >

                <TextView
                    android:id="@+id/tvabout1"
                    android:layout_width="wrap_content"
                    android:layout_height="20dp"
                    android:layout_gravity="center"
                    android:text="»"
                    android:textSize="20dp" />
            </LinearLayout>

        </LinearLayout>

          <LinearLayout 
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:layout_marginTop="10dp"
            android:layout_marginLeft="30dp"
            android:layout_marginRight="30dp">

            <TextView 
                android:id="@+id/tvpopupservices"
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:text="ABOUT"
                android:textSize="17dp"
                android:layout_marginLeft="10dp"/>
            <LinearLayout 
                android:layout_height="wrap_content"
                android:layout_width="match_parent"
                android:gravity="right|center">

                <TextView
                    android:id="@+id/tvservices1"
                    android:layout_width="wrap_content"
                    android:layout_height="20dp"
                    android:text="»"
                    android:textSize="20dp" 
                    android:layout_gravity="center"/>

            </LinearLayout>
        </LinearLayout>

           <LinearLayout 
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:layout_marginTop="10dp"
            android:layout_marginLeft="30dp"
            android:layout_marginRight="30dp">

            <TextView 
                android:id="@+id/tvpopupcontact"
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:text="CONTACT"
                android:textSize="17dp"
                android:layout_marginLeft="10dp"/>
            <LinearLayout 
                android:layout_height="wrap_content"
                android:layout_width="match_parent"
                android:gravity="right|center">

                <TextView
                    android:id="@+id/tvwork1"
                    android:layout_width="wrap_content"
                    android:layout_height="20dp"
                    android:text="»"
                    android:textSize="20dp" 
                    android:layout_gravity="center"/>

            </LinearLayout>
        </LinearLayout>
</LinearLayout>

请帮帮我, 谢谢。

【问题讨论】:

  • 您可以根据需要选择自定义对话框。您可以根据需要进行修改
  • 但是我想在菜单中你能做到吗?
  • 是的,你可以点击菜单项打开它
  • 你能给我它的代码吗?
  • 我可以给你一个想法。现在由你决定如何实现代码。在 Internet 上搜索自定义对话框的示例。你会得到很多东西..

标签: android popup


【解决方案1】:

插入 popupWindow.showAsDropDown(ivmainmenu, 50, -30); popupWindow.setHeight(200); popupWindow.setWidth(400);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-03
    • 1970-01-01
    • 2019-03-18
    • 1970-01-01
    • 2015-05-23
    • 1970-01-01
    相关资源
    最近更新 更多