I just implemented a ListView inside a LinearLayout, but I need to define the height of the LinearLayout (it has to be 50% of the screen height).
<LinearLayout
android:id="@+id/widget34"
android:layout_width="300px"
android:layout_height="235px"
android:orientation="vertical"
android:layout_below="@+id/tv_scanning_for"
android:layout_centerHorizontal="true">
<ListView
android:id="@+id/lv_events"
android:textSize="18sp"
android:cacheColorHint="#00000000"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/tv_scanning_for"
android:layout_centerHorizontal="true">
</ListView>
</LinearLayout>
Is that possible?
I did something similar for a button and an EditText, but doesn't seem to work on Layouts.
This is my Code:
//capture the size of the devices screen
Display display = getWindowManager().getDefaultDisplay();
double width = display.getWidth();
//my EditText will be smaller than full screen (80%)
double doubleSize = (width/5)*4;
int editTextSize = (int) doubleSize;
//define the EditText
userName = (EditText) this.findViewById(R.id.userName);
password = (EditText) this.findViewById(R.id.password);
//set the size
userName.setWidth(editTextSize);
password.setWidth(editTextSize);
This is my android:layout_height=50% activity:
style:
You should do something like that:
Also use dp instead px or read about it here.
This kind of worked for me. Though FAB doesn't float independently, but now it isn't getting pushed down.
Observe the weights given inside the LinearLayout
Hope this helps :)
You can use
android:weightSum="2"
on the parent layout combined withandroid:layout_height="1"
on the child layout.it's so easy if you want divide your screen two part vertically ( top30% + bottom70%)
This is easy to do in xml. Set your top container to be a LinearLayout and set the orientation attribute as you wish. Then inside of that place two linearlayouts that both have "fill parent" on width and height. Finally, set the weigth attribute of those two linearlayouts to 1.