Layout format: `
<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" > </LinearLayout> </LinearLayout> </ScrollView>`
Get device screen height: Point size = new Point(); getWindowManager().getDefaultDisplay().getSize(size); int screenHeight = size.y; Point size = new Point(); getWindowManager().getDefaultDisplay().getSize(size); int screenHeight = size.y;
Locate LinearLayout: LinearLayout layout = (LinearLayout)findViewById(R.id.layout1);
Set the height of the layout depending on the height of the screen that you received earlier: LayoutParams params = layout.getLayoutParams(); params.height = screenHeight - getStatusBarHeight(); LayoutParams params = layout.getLayoutParams(); params.height = screenHeight - getStatusBarHeight();
Done. Be sure to call all of these methods in the onCreate method.
Hope this helps!
source share