问题描述
当我启动仿真器并进入使用此代码的屏幕时,它会显示大多数文本信息,但会截断屏幕顶部(无法向上滚动),但在底部留出一些空间.
When I launch the emulator and enter the screen which uses this code it shows most of the text information but cuts off the top of the screen (cant scroll up) but leaves a bit of space at the bottom.
这是代码;
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:visibility="visible"
android:fillViewport="true"
android:id="@+id/backgroundImage" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center"
android:padding="10dip" >
<ImageView
android:id="@+id/earthSymbolImageView"
android:layout_width="25dp"
android:layout_height="25dp"
android:src="@drawable/earthsymbol" />
<TextView
android:id="@+id/earth_content1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/earth_title"
android:gravity="center"
android:textColor="#FFFFFF"
android:textSize="20sp" />
<TextView
android:id="@+id/earth_content2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/earth_text"
android:textColor="#FFFFFF" />
<Button
android:id="@+id/backButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/back" />
</LinearLayout>
</ScrollView>
有人知道为什么会这样吗?
Does anyone know why would this be happening?
推荐答案
这是由于LinearLayout中的layout_gravity引起的.由于您的LinearLayout位于ScrollView内,因此您可能只是尝试水平居中(此后就不会在ScrollView内垂直居中).像这样指定LinearLayout使其水平居中应该可以解决问题:
This is being caused because of the layout_gravity in your LinearLayout. Since your LinearLayout is inside a ScrollView you are probably just trying to center horizontally (centering vertically inside a ScrollView doesn't make since). Specifying your LinearLayout to center horizontally like this should do the trick:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center_horizontal"
android:padding="10dip" >
这篇关于ScrollView切断顶部并在底部留出空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!