2014-02-17 45 views
0

我想表明我的图像(菜单)的点击应用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> 

请帮忙米e, 谢谢。

+0

你可以根据需要去定制对话框。你可以根据你的需要修改它 –

+0

但我想在菜单中可以做到吗? – akky777

+0

是的,你可以打开它,点击菜单项' –

回答

-2

insted popupWindowow.showAsDropDown(ivmainmenu,50,-30); popupWindow.setHeight(200); popupWindow.setWidth(400);