Android 滚动视图中的全屏布局
我想在ScrollView中有2个布局。第一个布局应在全屏上,第二个布局应在第一个布局下方。当活动开始时,不可能看到第二个布局。第二种布局可以在滚动屏幕后看到。请看一下我的图片,以便更好地理解 布局代码:`Android 滚动视图中的全屏布局,android,android-layout,scrollview,Android,Android Layout,Scrollview,我想在ScrollView中有2个布局。第一个布局应在全屏上,第二个布局应在第一个布局下方。当活动开始时,不可能看到第二个布局。第二种布局可以在滚动屏幕后看到。请看一下我的图片,以便更好地理解 布局代码:` <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match
<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>`
`
获取设备屏幕高度:
点大小=新点();
getWindowManager().getDefaultDisplay().getSize(大小);
int screenHeight=size.y代码>
查找线性布局:
LinearLayout布局=(LinearLayout)findViewById(R.id.layout1);
根据先前获得的屏幕高度设置布局的高度:
LayoutParams params=layout.getLayoutParams();
params.height=屏幕高度-getStatusBarHeight();
完成了。确保在onCreate方法中调用所有这些方法
希望这有帮助 谢谢,第一次就完美了!我想强调一下这个代码,让其他人阅读这个问题。然后只需更改代码行params.height=screenHeight-getStatusBarHeight()
它确实有效!!!(欢迎使用Android——简单的任务极其复杂)。Kotlin有解决方案吗?还有一种解决方案,所有的事情都只在.xml文件中完成吗?