Design android app for fitting all screens -


i'm trying build app android , created xml file fragment. in preview, nexus 4 can see items(buttons, text view, etc.) taking space, when run app on phone (s6 edge +) there 1/5 of screen free. height set on @ wrap_content , use padding in dp units.

how can go problem ? should replace 'wrap content' specific value heights ?

my xml file:

 <?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     android:orientation="vertical" android:layout_width="match_parent"     android:background="@drawable/gradient"     android:layout_height="match_parent">      <textview         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:paddingtop="35dp"         android:text="title1"         android:id="@+id/textview"         android:textcolor="#fff"         android:layout_gravity="center_horizontal"         android:textsize="30dp" />      <textview         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:paddingtop="5dp"         android:textcolor="#fff"         android:text="title2"         android:id="@+id/textview3"         android:textsize="15dp"         android:layout_gravity="center_horizontal" />      <linearlayout         android:layout_width="match_parent"         android:paddingtop="15dp"         android:paddingleft="100dp"         android:layout_height="wrap_content">          <imageview             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:background="@drawable/first"             android:layout_marginright="15dp"             android:id="@+id/imageview" />          <imageview             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:layout_centerhorizontal="true"             android:layout_marginright="17dp"             android:background="@drawable/second"             android:id="@+id/imageview2" />          <imageview             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:background="@drawable/third"             android:id="@+id/imageview3" />     </linearlayout>      <button         android:layout_width="270dp"         android:layout_margintop="15dp"         android:background="@drawable/btnstyle"         android:layout_height="wrap_content"         android:text="button3"         android:gravity="left|center_vertical"         android:paddingleft="65dp"         android:textcolor="#fff"         android:id="@+id/button1"         android:layout_gravity="center_horizontal" />      <button         android:layout_width="270dp"         android:layout_margintop="15dp"         android:background="@drawable/btnstyle"         android:layout_height="wrap_content"         android:text="button4"         android:gravity="left|center_vertical"         android:paddingleft="65dp"         android:textcolor="#fff"         android:id="@+id/button2"         android:layout_gravity="center_horizontal" />      <button         android:layout_width="270dp"         android:layout_margintop="15dp"         android:background="@drawable/btnstyle"         android:layout_height="wrap_content"         android:text="button5"         android:gravity="left|center_vertical"         android:paddingleft="65dp"         android:textcolor="#fff"         android:id="@+id/button3"         android:layout_gravity="center_horizontal" />      <button         android:layout_width="270dp"         android:layout_margintop="15dp"         android:background="@drawable/btnstyle"         android:layout_height="wrap_content"         android:text="button6"         android:gravity="left|center_vertical"         android:paddingleft="65dp"         android:textcolor="#fff"         android:id="@+id/button4"         android:layout_gravity="center_horizontal" />      <button         android:layout_width="270dp"         android:layout_margintop="15dp"         android:background="@drawable/btnstyle"         android:layout_height="wrap_content"         android:text="button7"         android:gravity="left|center_vertical"         android:paddingleft="65dp"         android:textcolor="#fff"         android:id="@+id/button5"         android:layout_gravity="center_horizontal" />      <button         android:layout_width="270dp"         android:layout_margintop="15dp"         android:background="@drawable/btnstyle"         android:layout_height="wrap_content"         android:text="button8"         android:gravity="left|center_vertical"         android:paddingleft="65dp"         android:alpha="0.7"         android:textcolor="#fff"         android:id="@+id/button6"         android:layout_gravity="center_horizontal" />  </linearlayout> 

ok did make changes,

although don't understand view supposed in layout. made layout in manner manage it's space multi-screen support, should consider making different layout depending on screen want target.

kindly try this

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:background="#ffffff"     android:orientation="vertical">      <linearlayout         android:layout_width="match_parent"         android:layout_height="0dp"         android:layout_weight="0.20"         android:orientation="vertical">          <textview             android:id="@+id/textview"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:layout_gravity="center_horizontal"             android:paddingtop="35dp"             android:text="title1"             android:textcolor="#000"             android:textsize="30dp" />          <textview             android:id="@+id/textview3"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:layout_gravity="center_horizontal"             android:paddingtop="5dp"             android:text="title2"             android:textcolor="#000"             android:textsize="15dp" />      </linearlayout>      <linearlayout         android:layout_width="match_parent"         android:layout_height="0dp"         android:layout_weight="0.10"         android:orientation="vertical">          <linearlayout             android:layout_width="match_parent"             android:layout_height="match_parent"             android:paddingleft="100dp"             android:paddingtop="15dp">              <imageview                 android:id="@+id/imageview"                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:layout_marginright="15dp"                 android:background="@android:color/holo_purple" />              <imageview                 android:id="@+id/imageview2"                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:layout_centerhorizontal="true"                 android:layout_marginright="17dp"                 android:background="@android:color/holo_purple" />              <imageview                 android:id="@+id/imageview3"                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:background="@android:color/holo_purple" />         </linearlayout>     </linearlayout>      <linearlayout         android:layout_width="match_parent"         android:layout_height="0dp"         android:layout_weight="0.75"         android:orientation="vertical">          <button             android:id="@+id/button1"             android:layout_width="270dp"             android:layout_height="0dp"             android:layout_weight="1"             android:layout_gravity="center_horizontal"             android:layout_margin="10dp"             android:background="@android:color/holo_purple"             android:gravity="left|center_vertical"             android:paddingleft="65dp"             android:text="button3"             android:textcolor="#fff" />          <button             android:id="@+id/button2"             android:layout_width="270dp"             android:layout_height="0dp"             android:layout_weight="1"             android:layout_gravity="center_horizontal"             android:layout_margin="10dp"             android:background="@android:color/holo_purple"             android:gravity="left|center_vertical"             android:paddingleft="65dp"             android:text="button4"             android:textcolor="#fff" />          <button             android:id="@+id/button3"             android:layout_width="270dp"             android:layout_height="0dp"             android:layout_weight="1"             android:layout_gravity="center_horizontal"             android:layout_margin="10dp"             android:background="@android:color/holo_purple"             android:gravity="left|center_vertical"             android:paddingleft="65dp"             android:text="button5"             android:textcolor="#fff" />          <button             android:id="@+id/button4"             android:layout_width="270dp"             android:layout_height="0dp"             android:layout_weight="1"             android:layout_gravity="center_horizontal"             android:layout_margin="10dp"             android:background="@android:color/holo_purple"             android:gravity="left|center_vertical"             android:paddingleft="65dp"             android:text="button6"             android:textcolor="#fff" />          <button             android:id="@+id/button5"             android:layout_width="270dp"             android:layout_height="0dp"             android:layout_weight="1"             android:layout_gravity="center_horizontal"             android:layout_margin="10dp"             android:background="@android:color/holo_purple"             android:gravity="left|center_vertical"             android:paddingleft="65dp"             android:text="button7"             android:textcolor="#fff" />          <button             android:id="@+id/button6"             android:layout_width="270dp"             android:layout_height="0dp"             android:layout_weight="1"             android:layout_gravity="center_horizontal"             android:layout_margin="10dp"             android:alpha="0.7"             android:background="@android:color/holo_purple"             android:gravity="left|center_vertical"             android:paddingleft="65dp"             android:text="button8"             android:textcolor="#fff" />      </linearlayout>   </linearlayout> 

output

output

update

things can distribute views equilibrium horizontally using layout_weight while making width 0dp, in given example showing 2 buttons taking space horizontally. pay attention it's width , layout_weight

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:gravity="center_horizontal"     android:orientation="horizontal">      <button         android:layout_width="0dp"         android:layout_height="wrap_content"         android:layout_margin="4dp"         android:layout_weight="0.5"         android:text="one"         android:textallcaps="false" />      <button         android:layout_width="0dp"         android:layout_height="wrap_content"         android:layout_margin="4dp"         android:layout_weight="0.5"         android:text="two"         android:textallcaps="false" />  </linearlayout> 

enter image description here

if want 2 views take equal space vertically can use following example, make parent layout have orientation vertical , view's height 0dp

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:orientation="vertical">      <imageview         android:layout_width="match_parent"         android:layout_height="0dp"         android:layout_weight="0.5"         android:src="@drawable/goku" />      <imageview         android:layout_width="match_parent"         android:layout_height="0dp"         android:layout_weight="0.5"         android:src="@drawable/gohan" />  </linearlayout> 

enter image description here


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -