2011-05-09 40 views
8

我需要设计一个GUI,其内容位于不滚动屏幕顶部的内容以及滚动顶部部分下方的内容。我想过使用非滚动部分的LinearLayout和滚动部分的ScrollView。但是,当我尝试在LinearLayout之后使用ScrollView时,出现运行时错误。是否可以将LinearLayout和ScrollView添加到父LinearLayout?我们可以在LinearLayout中使用ScrollView吗?

+0

@ user479129:使用'ADB logcat',DDMS,或在Eclipse中DDMS角度来考察logcat的,看看你的 “运行时错误” 相关的堆栈跟踪。 – CommonsWare 2011-05-09 14:31:25

回答

17

可以

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" 
    > 

    <!-- non-scrolling top pane --> 
    <LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="0dp" 
    android:layout_weight="1" 
    > 

    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="This text will not scroll" 
     /> 

    </LinearLayout> 

    <!-- scrolling bottom pane --> 
    <ScrollView 
    android:layout_width="fill_parent" 
    android:layout_height="0dp" 
    android:layout_weight="1" 
    > 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     > 

     <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="This text will scroll if it is long enough..." 
     /> 

    </LinearLayout> 

    </ScrollView> 

</LinearLayout> 
+1

这似乎不适用于api版本24,但在api版本22中。 – SamG 2016-07-28 11:28:13