2017-01-12 46 views
0

我正在创建一个需要ScrollViews的应用程序,我正在使用它们时遇到麻烦。当我添加滚动视图的应用程序的布局向上移动,我不知道是什么问题。我怎样才能摆脱这个问题? 之前和之后我加入了滚动的屏幕截图低于Before Scrollview & After Scrollview如何在android中使用滚动条

下面是滚动型后的代码

<RelativeLayout 
    android:id="@+id/activity_main" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@color/backgroundColor" 
    android:orientation="vertical" 
    android:padding="24dp" 
    tools:context=".activity.MainActivity"> 

    <ImageView 
     android:id="@+id/city_image_view" 
     android:layout_width="72dp" 
     android:layout_height="72dp" 
     android:layout_centerHorizontal="true" 
     android:layout_marginTop="60dp" 
     android:src="@drawable/ic_place_black_36dp" /> 

    <TextView 
     android:id="@+id/city_text_view" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/city_image_view" 
     android:layout_centerHorizontal="true" 
     android:layout_marginTop="16dp" 
     android:fontFamily="sans-serif-medium" 
     android:text="@string/select_city" 
     android:textSize="24sp" /> 

    <Spinner 
     android:id="@+id/city_spinner" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignLeft="@id/city_text_view" 
     android:layout_alignRight="@id/city_text_view" 
     android:layout_below="@id/city_text_view" 
     android:layout_centerHorizontal="true" 
     android:layout_marginTop="16dp" 
     android:focusableInTouchMode="true" 
     android:spinnerMode="dropdown" /> 

    <Button 
     android:id="@+id/city_button" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignLeft="@id/city_text_view" 
     android:layout_below="@id/city_spinner" 
     android:layout_marginTop="36dp" 
     android:text="@string/send_button" /> 

</RelativeLayout> 

回答

0

添加android:fillViewport="true"属性来滚动视图。它会帮助你获得完美的布局。

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fillViewport="true" 
    xmlns:tools="http://schemas.android.com/tools"> 
<!--Enter your code here--> 

</ScrollView>