滚动视图中的全屏布局

时间:2014-04-18 16:22:12

标签: android android-layout scrollview

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

enter image description here

1 个答案:

答案 0 :(得分: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>`

获取设备屏幕高度: 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方法中调用所有这些方法。

希望这有帮助!

相关问题