2013-06-24 42 views
2

中調整彈出式下拉對話框的大小我想創建一個帶有複選框的多選微調框,但我不知道如何這樣做,所以我想出了一個替代下拉列表multislect popupdialog。我能夠顯示彈出式窗口,但是我的問題是......正如您在圖片中看到的那樣,彈出窗口不會在信息類型框中對齊......您能幫助我嗎?如何在android

The picture show the a button and a popupwindow as a dropdown dialog in my project

這裏是我在popupInformationType.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/PopUpViewInformationType" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:layout_marginLeft="10dp" 
android:layout_marginRight="10dp" 
android:orientation="vertical"> 

<ListView 
    android:id="@+DropDownList/dropDownListInfoType" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:background="#d3d3d3" 
    android:cacheColorHint="@color/cachecolorhint" 
    android:divider="#000" 
    android:dividerHeight="0.5dp" > 
</ListView> 
</LinearLayout> 

代碼,這裏是我的dro_down_list_infotype.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/linearLayout1" 
android:layout_width="wrap_content" 
android:layout_height="fill_parent"> 

<CheckBox 
    android:id="@+DropDownList/checkboxInfoType" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:button="@drawable/selector_checkbox" 
    android:layout_marginLeft="10dp" /> 

<TextView 
    android:id="@+DropDownList/SelectOptionInfoType" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textColor="#000" 
    android:layout_gravity="center_vertical"/> 

</LinearLayout> 

代碼,這裏是我的代碼中的一部分調用彈出窗口的MainActivity

private void initiatePopUpInfoType(ArrayList<String> informationTypes, TextView tv_InformationType){ 
    LayoutInflater inflater = (LayoutInflater)IreportMain.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 

    //get the pop-up window i.e. drop-down layout 
    LinearLayout layoutInfoType = (LinearLayout)inflater.inflate(R.layout.popup_informationtype, (ViewGroup)findViewById(R.id.PopUpViewInformationType)); 

    //get the view to which drop-down layout is to be anchored 
    RelativeLayout layout2 = (RelativeLayout)findViewById(R.id.relativeLayout2); 
    pwInfoType = new PopupWindow(layoutInfoType, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, true); 


    pwInfoType.setBackgroundDrawable(new BitmapDrawable()); 
    pwInfoType.setTouchable(true); 

    //let pop-up be informed about touch events outside its window. This should be done before setting the content of pop-up 
    pwInfoType.setOutsideTouchable(true); 
    pwInfoType.setHeight(LayoutParams.WRAP_CONTENT); 

    //dismiss the pop-up i.e. drop-down when touched anywhere outside the pop-up 
    pwInfoType.setTouchInterceptor(new OnTouchListener() { 

     public boolean onTouch(View v, MotionEvent event) { 
      // TODO Auto-generated method stub 
      if (event.getAction() == MotionEvent.ACTION_OUTSIDE) { 
       pwInfoType.dismiss(); 
       return true;      
      } 
      return false; 
     } 
    }); 

    //provide the source layout for drop-down 
    pwInfoType.setContentView(layoutInfoType); 

    //anchor the drop-down to bottom-left corner of 'layout2' 
    pwInfoType.showAsDropDown(layout2); 

    //populate the drop-down list 
    final ListView listInfoType = (ListView) layoutInfoType.findViewById(R.DropDownList.dropDownListInfoType); 
    InfoTypeListAdapter adapter = new InfoTypeListAdapter(this, informationTypes, tv_InformationType); 
    listInfoType.setAdapter(adapter); 
} 
+0

ü也可以嘗試用pwInfoType.setWidth(tv_InformationType.getWidth()); –

回答

1

我已經解決了。我只是把這兩個listview放在一個xml文件中,然後創建了兩列。這是我在xml中的代碼。

<LinearLayout 
android:id="@+id/PopUpView" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:layout_marginLeft="10dp" 
android:layout_marginRight="10dp" 
android:orientation="horizontal"> 

<ListView 
    android:id="@+DropDownList/dropDownListBrand" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:background="#d3d3d3" 
    android:cacheColorHint="@color/cachecolorhint" 
    android:divider="#000" 
    android:dividerHeight="0.5dp" 
    android:layout_weight="1" 
    android:layout_marginLeft="10dp" 
    android:layout_marginRight="2dp"> 
</ListView> 

<ListView 
    android:id="@+DropDownList/dropDownListInfoType" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:background="#d3d3d3" 
    android:cacheColorHint="@color/cachecolorhint" 
    android:divider="#000" 
    android:dividerHeight="0.5dp" 
    android:layout_weight="1" 
    android:layout_gravity="right" 
    android:layout_marginRight="10dp" 
    android:layout_marginLeft="2dp"> 
</ListView> 

+0

你可以接受你自己的答案,所以對於有同樣問題的其他人來說更容易看到這個答案有一個被接受的問題。 –