Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
507 views
in Technique[技术] by (71.8m points)

android - ScrollView cuts off the top and leaves space at the bottom

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.

Here is the code;

    <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?

question from:https://stackoverflow.com/questions/15922866/scrollview-cuts-off-the-top-and-leaves-space-at-the-bottom

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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" >

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...