在我的Android应用中,我有一个标签Activity.在其中一个标签中,我有两个TextViews和两个EditTexts.
第一个EditText只有一行,那没关系.不过,我想其他的EditText,android:id="@+id/paste_code",占用的剩余空间,但无论我做什么它,它会只显示一行.我不想手动设置行数,因为屏幕上适合的数字因设备而异.
这是相关的代码.它嵌套在选项卡的所有必要组件中Activity.
<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>
Run Code Online (Sandbox Code Playgroud)
由于接受的答案并没有完全解决这个问题,所以这里有一个适当的解决方案,让人们在搜索时来到这里:
首先,来自Android开发团队的Romain Guy在这篇博客文章中解决了这个问题:
http://www.curious-creature.org/2010/08/15/scrollviews-handy-trick/
基本上,您ScrollView需要包含android:fillViewport="true"属性.
如果你做完之后事情不起作用,这里有几件事需要检查:
ScrollView(例如a LinearLayout)内部的布局需要有layout_height="wrap_content"layout_height="wrap_content"layout_weight="1.0"或类似minLines="3"如果您不希望它/它们缩小太多,请不要忘记在要展开的视图中设置或类似.