android - 如何调整android中弹出下拉对话框的大小

标签 android listview checkbox spinner

我正在尝试创建一个带有复选框的多选微调器,但我不知道该怎么做,所以我想出了一个替代的下拉多选弹出对话框。我能够显示弹出窗口,但我的问题是..正如您在图片中看到的那样,弹出窗口没有与信息类型框对齐...您能帮我解决这个问题吗?

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);
}

最佳答案

我已经解决了。我只是将两个 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>

关于android - 如何调整android中弹出下拉对话框的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17267789/

相关文章:

android - tif 和 tiff 图像未显示带有 React Native 的 Image 组件的 android

Android - 我可以使用什么 API 来查看设备是否支持 BLE 中央模式?

C# 将 ListView 项目与对象绑定(bind)

c# - ListView 的 EditItemTemplate 中的 AsyncFileUpload

vue.js - Vue : binding with v-model in custom checkbox component doesn't work

android - 使用菜单按钮时的导航组件

java - 如何以编程方式为应用程序设置锁定或 pin

android - 如何禁用回收者查看项目选择

javascript - jquery 按名称访问复选框

javascript - 计算多个面板中选中的复选框的数量,并使用 jQuery/JavaScript 在正确的面板中显示相关数量