android - how to make app a percent of the screen size -
i trying make app image below, setting app percent of whole screen (not setting dp), no matter type of phone using, app take same screen percentage. main activity consists of 2 fragments in 1 linearlayout.
android:layout_width="300dp" android:layout_height="300dp" xmlns:tools="http://schemas.android.com/tools" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_gravity="center" android:background="@drawable/rounded_edges" android:theme="@style/theme.appcompat.light.dialog.alert"> <!-- create container (framelayout) body fragment switch other fragments on button clicks--> <fragment android:id="@+id/menufragment" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_margin="5dp" class="it.anddev.bradipao.janus.menufragment" tools:layout="@layout/fr_menu"> </fragment> <framelayout android:id="@+id/container" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="end" />
i want height , width percent of phone height , width shown here.
you should use linearlayout container, , use these properties:
- weightsum in linearlayout, set 1.
layout_weight in every child of linearlayout. example:
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="match_parent" android:weightsum="1"> <linearlayout android:orientation="vertical" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="0.75"> .... </linearlayout> <linearlayout android:orientation="vertical" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="0.25"> .... </linearlayout> </linearlayout>
first layout take 75% of screen , second 25%.
note when using weights, height and/or width has 0dp. can make complex need.
Comments
Post a Comment