android - ScrollView 中的全屏布局

标签 android android-layout scrollview

我想在 ScrollView 中有 2 个布局。第一个布局应在全屏上,第二个布局应在第一个布局下方。当 Activity 开始时,不可能看到第二个布局。滚动屏幕后可以看到第二种布局。请看一下我的图片以便更好地理解。

enter image description here

最佳答案

布局代码:`

<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>`

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

找到线性布局: LinearLayout layout = (LinearLayout)findViewById(R.id.layout1);

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

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

希望这对您有所帮助!

关于android - ScrollView 中的全屏布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23158072/

相关文章:

android - layout_constrainedWidth 无法正常工作

java - 使用 SQLite 在 android 中获取下一个值

android - Playstore:在Android Studio list 中制作的应用的 “0 devices supported”和

android - 设计自定义 Android View 所需的帮助

android - 连接时,SQLite 是否将整个数据库文件加载到内存中?

android - 如何在 CollapsingToolbarLayout 中使用 PercentRelativeLayout?

Android:如何动态放置具有相对间距的 View

scrollview - SwiftUI - ScrollView 没有一直滚动到底部

javascript - 如何使用数据库中的纯文本填充 android 中的 webview 并能够处理换行符

android - Android 中微调控件的图形问题