【问题标题】:Spinner not filling its parent微调器未填充其父级
【发布时间】:2011-05-24 04:20:57
【问题描述】:

我在带有主题对话框的活动中使用微调器。 无论我做什么,我都无法让微调器填充父宽度 - 那些总是只有文本的长度。这是我的布局定义。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="match_parent"  android:layout_width="match_parent" android:orientation="vertical">
        <LinearLayout android:id="@+id/weight_units"
            android:layout_width="match_parent" android:gravity="top|center_vertical|center_horizontal"
            android:orientation="horizontal" android:layout_marginBottom="3dip" android:layout_marginTop="3dip"  android:layout_height="wrap_content">
            <TextView android:layout_marginRight="3dip" android:id="@+id/spinner_lbl"
                android:text="@string/weight_units"
                android:layout_marginLeft="3dip" android:layout_height="wrap_content"
                android:layout_width="match_parent" android:layout_gravity="center_vertical|center_horizontal"  android:layout_weight="1" ></TextView>
            <Spinner android:id="@+id/weight_spinner" android:layout_height="wrap_content" android:layout_weight="1" android:layout_width="match_parent"></Spinner>
        </LinearLayout>

        <LinearLayout android:orientation="vertical"
            android:paddingTop="2dip" android:paddingBottom="2dip" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1">
            <TextView android:layout_width="match_parent"
                android:layout_height="wrap_content" android:layout_marginTop="10dip"
                android:text="@string/calc_formula_prompt" />
            <Spinner android:id="@+id/calc_spinner" android:layout_height="wrap_content" android:prompt="@string/calc_formula_prompt" android:layout_width="fill_parent"/>
        </LinearLayout>

要清楚 - 我确实希望活动以对话框的形式打开,并抓住大部分屏幕 - 但是当我横向时 - 微调器不会拉伸到完整的父宽度。

提前致谢

【问题讨论】:

  • 那个压痕伤了我的眼睛

标签: android android-layout spinner


【解决方案1】:

问题在于该视图被夸大并用作 ViewFlipper 中的一种竞争。 缺少并导致这种烦人行为的代码是使用正确的 LayoutParams 将鳍状肢添加到其父布局中。

    flipper = new MyViewFlipper(this, gestureDetector);
    lay1.addView(flipper,new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));

对于不完整的问题,我深表歉意 - 我不知道这可能与将鳍状肢添加到其父级的方式有关。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多