If I define ListView's height in XML the layout gravity is working, but I want calculate the height programmatically, but in this case the layouts sliding over one another.
The XML:
<EditText android:id="@+id/inputSearch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:hint="Search..."
android:background="@drawable/bar"
android:inputType="text"
android:layout_gravity="top" />
<ListView
android:id="@+id/contactlist"
android:layout_width="wrap_content"
android:layout_height="400dp"
android:layout_gravity="bottom" />
Code:
TypedValue tv = new TypedValue();
if (getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true))
{
actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data,getResources().getDisplayMetrics());
}
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int layoutHeight = size.y - 59 - actionBarHeight;
listView.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT,layoutHeight));
Try like this
LayoutParams params = listView.getLayoutParams();
params.height = layoutHeight;
listView.setLayoutParams(params);