滚动视图中的全屏布局

Mat*_*osk 8 android scrollview android-layout

我想在ScrollView中有2个布局.第一个布局应该在全屏幕上,第二个布局应该在第一个布局下面.活动开始时,无法看到第二个布局.滚动屏幕后可以看到第二种布局.请查看我的图片以便更好地理解.

在此输入图像描述

Eth*_*mas 12

布局代码:`

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

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

    <LinearLayout
        android:id="@+id/layout1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >


    </LinearLayout>

    <LinearLayout
        android:id="@+id/layout2"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:orientation="vertical" >

        <!-- this layout can be any height you want -->

    </LinearLayout>
</LinearLayout>

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

获取设备屏幕高度: Point size = new Point(); getWindowManager().getDefaultDisplay().getSize(size); int screenHeight = size.y;

找到LinearLayout: LinearLayout layout = (LinearLayout)findViewById(R.id.layout1);

根据您之前获得的屏幕高度设置布局的高度: LayoutParams params = layout.getLayoutParams(); params.height = screenHeight - getStatusBarHeight();

完成.请务必在onCreate方法中调用所有这些方法.

希望这可以帮助!