设置文本框宽度,其剩余宽度

问题描述:

请看看下面的代码设置文本框宽度,其剩余宽度

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

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     > 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/firstNumber" 
     /> 

    <EditText 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     /> 

    </LinearLayout> 

</LinearLayout> 

在这里,文本框的大小(宽度)非常小。我试图将其设置为适合剩余的宽度,但正如您所看到的那样,它会失败。我也使用了android:weight=1。请帮忙,我怎样才能将文本框的宽度设置为剩余宽度?

也许你需要像下面那样改变水平LinearLayout。变化宽度至match_parent

<LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     > 

并添加android:weight=1到TextView的

+0

非常感谢!这有帮助! +1从我:) –

尝试此

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="fill_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" 
android:background="#FFFFFF" 
> 
<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    > 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/firstNumber" 
    android:layout_weight="0" 
    /> 

<EditText 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    /> 

</LinearLayout> 

+0

非常感谢回复。 +1从我:) –

先给内的LinearLayout的layout_width作为match_parent

android:layout_width="match_parent"

+0

非常感谢答复。 +1我:) –