8
我需要設計一個GUI,其內容位於不滾動屏幕頂部的內容以及滾動頂部部分下方的內容。我想過使用非滾動部分的LinearLayout和滾動部分的ScrollView。但是,當我嘗試在LinearLayout之後使用ScrollView時,出現運行時錯誤。是否可以將LinearLayout和ScrollView添加到父LinearLayout?我們可以在LinearLayout中使用ScrollView嗎?
我需要設計一個GUI,其內容位於不滾動屏幕頂部的內容以及滾動頂部部分下方的內容。我想過使用非滾動部分的LinearLayout和滾動部分的ScrollView。但是,當我嘗試在LinearLayout之後使用ScrollView時,出現運行時錯誤。是否可以將LinearLayout和ScrollView添加到父LinearLayout?我們可以在LinearLayout中使用ScrollView嗎?
可以
<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>
這似乎不適用於api版本24,但在api版本22中。 – SamG 2016-07-28 11:28:13
@ user479129:使用'ADB logcat',DDMS,或在Eclipse中DDMS角度來考察logcat的,看看你的 「運行時錯誤」 相關的堆棧跟蹤。 – CommonsWare 2011-05-09 14:31:25