Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/200.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/349.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android EditText赢得';不要占用剩余的空间_Android - Fatal编程技术网

Android EditText赢得';不要占用剩余的空间

Android EditText赢得';不要占用剩余的空间,android,Android,在我的Android应用程序中,我有一个选项卡式的活动。在其中一个选项卡中,我有两个TextViews和两个EditTexts 第一个EditText只有一行,这很好。但是,我希望另一个EditText,android:id=“@+id/paste_code”,占据剩余的空间,但无论我如何处理它,它都只会显示一行。我不想手动设置行数,因为屏幕上显示的行数会因设备而异 这是相关代码。它嵌套在选项卡式活动的所有必要组件中 <ScrollView android:id="@+id/bas

在我的Android应用程序中,我有一个选项卡式的
活动
。在其中一个选项卡中,我有两个
TextView
s和两个
EditText
s

第一个
EditText
只有一行,这很好。但是,我希望另一个
EditText
android:id=“@+id/paste_code”
,占据剩余的空间,但无论我如何处理它,它都只会显示一行。我不想手动设置行数,因为屏幕上显示的行数会因设备而异

这是相关代码。它嵌套在选项卡式
活动的所有必要组件中

<ScrollView
    android:id="@+id/basicTab"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" 
        android:layout_weight="1" >
        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Paste title"
            android:layout_weight="0" />
        <EditText
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:hint="@string/paste_title_hint"
            android:id="@+id/paste_title"
            android:lines="1"
            android:gravity="top|left"
            android:layout_weight="0" />
        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Paste text"
            android:layout_weight="0" />
        <EditText
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:hint="@string/paste_hint"
            android:id="@+id/paste_code"
            android:gravity="top|left"
            android:layout_weight="1" />
    </LinearLayout>
</ScrollView>


问题似乎来自您对ScrollView的使用。我使用ScrollView作为父容器测试了您的代码,并遇到了相同的问题。但是,如果我将ScrollView替换为LinearLayout,则第二个编辑文本将正确展开以填充整个屏幕。问题一定是ScrollView被设计成尽可能小的尺寸,不管你在android:layout\u height中做了什么设置。我尝试了另外几个布局,例如,使用上面的
layout\u
和下面的
layout\u的RelativeLayout,但这些仅影响其最大大小,而不影响其空时的大小。不幸的是,这意味着我不知道如何解决你的问题。。。有没有一种方法可以重新设计布局,将ScrollView以外的内容用作父容器?

由于接受的答案不能完全解决这种情况,因此,对于搜索时遇到这种情况的用户,这里有一个适当的解决方案:

首先,Android开发团队的Romain Guy在这篇博文中很好地阐述了这一点:

本质上,您的
ScrollView
需要包含
android:fillViewport=“true”
属性

如果一旦你这样做了,事情就不起作用了,这里有几件事需要检查:

  • 滚动视图
    内的布局(如
    线性布局
    )需要具有
    布局\u height=“wrap\u content”
  • 要展开的视图应具有
    layout\u height=“wrap\u content”
  • 要展开的视图应具有
    布局\u weight=“1.0”
    或类似布局

如果不想让视图缩小太多,请不要忘记在要展开的视图中设置
minLines=“3”
或类似项。

是的,如果没有滚动视图,此选项卡可能很好,因为(如果我记得正确的话)编辑文本有自己的滚动条。我会玩一个线性布局。谢谢。另外,我刚刚发现它肯定了你关于android的说法:layout_height不做任何事情,并提供了另一个XML属性,使它占据了屏幕的其余部分。如果这不起作用,我会求助于线性布局;谢谢你。我对另一个答案进行了评论,并与解决我问题的另一个SO问题进行了链接。