xml布局中的ScrollView?

Yaz*_*eeb 0 xml layout android scrollview

我在布局中使用 ScrollView,如下所示:

 <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
        <!-- my rest xml code-->
    </LinearLayout>

</ScrollView>
Run Code Online (Sandbox Code Playgroud)

然后我的布局预览显示如下:

这是我的布局预览的屏幕截图

为什么布局看起来像这样?!

use*_*117 6

这只是因为您用作ScrollView根视图。

根据需要更改根视图(LinearLayout/RelativeLayout/FrameLayout)并在根视图下添加 ScrollView 作为子布局。

例如

<LinearLayout
 xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="match_parent"
 android:layout_height="match_parent" > 
<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
        <!-- your rest xml code-->
    </LinearLayout>

</ScrollView>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

希望能帮助到你。