Android 如何从字体宽度设置视图宽度

Android 如何从字体宽度设置视图宽度,android,width,spinner,font-size,Android,Width,Spinner,Font Size,我有一个EditText和一个水平布局的微调器。我希望微调器的大小与容纳最宽文本所需的大小相同,而EditText则占据剩余的空间。有没有一个简单的方法可以做到这一点 例如,理想情况下,我希望将微调器的宽度指定为平均字体宽度的倍数,在xml文件中声明为属性 否则,我想我需要在运行时做一些事情,比如获取微调器中每个项目的文本宽度,并为单选按钮图标获取最大值+一些余量 这是我的xml: <LinearLayout xmlns:android="http://schemas.android.

我有一个EditText和一个水平布局的微调器。我希望微调器的大小与容纳最宽文本所需的大小相同,而EditText则占据剩余的空间。有没有一个简单的方法可以做到这一点

例如,理想情况下,我希望将微调器的宽度指定为平均字体宽度的倍数,在xml文件中声明为属性

否则,我想我需要在运行时做一些事情,比如获取微调器中每个项目的文本宽度,并为单选按钮图标获取最大值+一些余量

这是我的xml:

<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="horizontal" >

  <EditText
    android:id="@+id/text"
    android:layout_weight="1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="@string/text" />

  <Spinner
    android:id="@+id/type"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:spinnerMode="dropdown"
    android:textAppearance="@android:style/TextAppearance.Medium" />
</LinearLayout>

谢谢。

试试这个

<LinearLayout
    android:id="@+id/rl"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_marginBottom="10dp"
    android:orientation="horizontal" >

    <EditText
        android:id="@+id/editText1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1" >
    </EditText>

    <Spinner
        android:id="@+id/spinner1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
</LinearLayout>


对。这应该行得通。我不知道为什么我忽略了这一点。事实上,它不起作用。它只为单选按钮提供了足够的宽度。单选按钮从何而来?有一个区别:我的声明为“下拉”。如果我把它拿出来,宽度就行了。但是,我更喜欢下拉列表,我在上面的帖子中添加了xml。