与LinearLayout中大量的无用的空白,滚动型 [英] Massive unwanted whitespace with LinearLayout in ScrollView
问题描述
我有一个自定义的ImageView的布局,以及两个TextEdits;一个在上面,下面的一个。为了使这个适合在多个屏幕上我有一个滚动型包围了整个事情。
然而,当滚动型加入大规模间隙(约屏幕的高度)出现在顶部文本编辑和ImageView的,并且ImageView的和底部的文本编辑之间
我只覆盖的onDraw()
方法在ImageView的(和我仍然呼吁 super.onDraw()
从那里)
这是我的布局:
< LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:方向=垂直> <的EditText
机器人:ID =@ + ID / top_text
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:EMS =10
机器人:提示=@字符串/ top_hint> < requestFocus的/>
< /&的EditText GT; < com.javanut13.gememerator.MImageView
机器人:ID =@ + ID / image_viewer
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:填充=0dp
机器人:SRC =@绘制/ ic_action_search/> <的LinearLayout
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT> <的EditText
机器人:ID =@ + ID / bottom_text
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:EMS =10
机器人:layout_weight =3
机器人:提示=@字符串/ bottom_hint/> <按钮
机器人:ID =@ + ID /按钮1
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_weight =1
机器人:文字=@字符串/ BUTTON_TEXT/>
< / LinearLayout中>
< / LinearLayout中>
好吧,事实证明,我的ImageView没有调整它的高度时,缩放图像,因此它会保持原始图像的高度(这从我的相机;约2000像素高),从而有上方和下方一个巨大的空间。
(图像不ImageView的调整:我碰到这个问题就来了),它说要添加的android:adjustViewBounds =真正的
来的ImageView的,它解决了这个问题。
I have a layout with a custom ImageView, and two TextEdits; one above and one below. To make this fit on multiple screens I have surrounded the whole thing with a ScrollView.
However, when the ScrollView is added a massive gap (approx. the height of the screen) appears between the top TextEdit and the ImageView, and the ImageView and the bottom TextEdit.
I am only overriding the onDraw()
method in the ImageView (and am still calling super.onDraw()
from there)
This is my layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<EditText
android:id="@+id/top_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="@string/top_hint" >
<requestFocus />
</EditText>
<com.javanut13.gememerator.MImageView
android:id="@+id/image_viewer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="0dp"
android:src="@drawable/ic_action_search" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<EditText
android:id="@+id/bottom_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:layout_weight="3"
android:hint="@string/bottom_hint" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/button_text" />
</LinearLayout>
</LinearLayout>
Ok, it turned out that my ImageView wasn't resizing its height when it scaled the image, and so it would keep the height of the raw image (which was from my camera; about 2000 pixels tall) and thus have a massive space above and below it.
I came across this question: (Image do not resize with ImageView) which says to add android:adjustViewBounds="true"
to the ImageView, which fixes the problem.
这篇关于与LinearLayout中大量的无用的空白,滚动型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!