At runtime, you can determine how much space your LinearLayout1 is taking up, and adjust its height only if it takes more than half of the screen. To do this, use following code.
Suppose you have given your LinearLayout1 the id as R.id.LL1, then using this code, you can ask android to adjust height of LL1 to 50%
int screenHeight, screenWidth;
//Code to determine screen's height and width.
Display display = getWindowManager.getDefaultDisplay();
if (android.os.Build.Version.SDK_INT>=13) {
Point size = new Point();
display.getSize(size);
screenHeight = size.x;
screenWidth = size.y;
}
else {
screenWidth = display.getWidth();
screenHeight = display.getHeight();
}
LinearLayout ll = (LinearLayout) findViewById(R.id.LL1);
int layoutHeight = ll.getLayoutParams().height; // gets layout's height
if ((layoutHeight * 2) > screenHeight) {
// true when LL1 takes more than half of screen, good time to set it back to 50% height
ll.getLayoutParams().height = screenHeight/2;
ll.requestLayout(); //Forces layout to be adjusted.
}
else {
//All good, no work required, so skip this else block
}