【问题标题】:Spinner height expands to bottom of screen微调器高度扩展到屏幕底部
【发布时间】:2015-06-23 07:34:15
【问题描述】:

我在布局中有一个带有微调器的片段。微调器 xml 是:

        <Spinner
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/spCategory"
            android:spinnerMode="dialog"
            android:dropDownWidth="match_parent"
            android:prompt="@string/label_category_select" />

填充微调器是这样完成的:

    List<Category> categories = categoryRepository.getAll();
    CategoryAdapter adapter = new CategoryAdapter(this.getActivity(), categories);
    adapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);

    spCategory= (Spinner)view.findViewById(R.id.spCategory);
    spCategory.setAdapter(adapter);

CategoryAdapter 扩展了 ArrayAdapter,我使用 ViewHolder 模式。适配器使用这个自定义布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/tvSpinnerRowId"
        android:visibility="gone">
    </TextView>

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/tvSpinnerRowName">
    </TextView>  
</RelativeLayout>

问题是布局中的微调器高度延伸到屏幕底部。

我错过了什么?

【问题讨论】:

    标签: android android-layout android-fragments


    【解决方案1】:

    尝试修改 .xml 文件中的以下行

    android:dropDownWidth="match_parent"
    

    android:dropDownWidth="300dp"
    

    或包装内容

    希望这会有所帮助!

    【讨论】:

      【解决方案2】:

      经过更多研究,您似乎无法操纵 Spinner 下拉菜单的高度,或者它的任何其他布局属性。

      这是因为下拉菜单实际上是一个弹出对话框,无法从 Spinner 视图中访问。

      这个答案说得很清楚:http://stackoverflow.com/a/1918655/529138

      因此,我必须使用问题中指定的 android:layout_marginBottom。

      【讨论】:

        猜你喜欢
        • 2011-09-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-07-20
        • 1970-01-01
        • 2017-03-10
        相关资源
        最近更新 更多