Best way to center content in android linear layout -


i've created following splash screen layout using android developer studio. wanted center content consist of 2 text views , image view. following xml.

<?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="@drawable/splash_gradient">  <relativelayout     android:layout_width="fill_parent"     android:layout_height="fill_parent">      <imageview id="@+id/splashscreen"         android:layout_width="100dp"         android:layout_height="250dp"         android:paddingbottom="100dp"         android:layout_centerinparent="true"         android:gravity="center_vertical|center_horizontal"         android:src="@drawable/splash_logo" />      <textview         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:text="sample"         android:layout_centerinparent="true"         android:fontfamily="@string/font_family_thin"         android:paddingtop="90dp"         android:paddingright="90dp"         android:textsize="35dp"         android:textcolor="#fff"         />      <textview         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:text="app"         android:layout_centerinparent="true"         android:fontfamily="@string/font_family_regular"         android:textsize="35dp"         android:paddingtop="90dp"         android:paddingleft="100dp"         android:textcolor="#fff"         />  </relativelayout> 

this following image.

enter image description here

is correct way center content or there better way achieve i'm looking for? please guide me. in advance.

if using padding center elements, wrong way because different results different screens.

see alternative, not one.

<?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="@drawable/splash_gradient"     android:gravity="center">      <relativelayout         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_gravity="center">          <imageview              android:id="@+id/splashscreen"             android:layout_width="100dp"             android:layout_height="250dp"             android:paddingbottom="100dp"             android:layout_alignparenttop="true"             android:layout_centerhorizontal="true"             android:src="@drawable/splash_logo" />          <linearlayout             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:layout_below="@id/splashscreen"             android:layout_centerhorizontal="true"             android:orientation="horizontal"             android:layout_margintop="10dp">              <textview                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:text="sample"                 android:textsize="35dp"                 android:textcolor="#fff"                 android:layout_marginend="15dp"                 android:layout_marginright="10dp"                 android:fontfamily="@string/font_family_thin"                 />              <textview                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:text="app"                 android:layout_centerinparent="true"                 android:textsize="35dp"                 android:textcolor="#fff"                 android:fontfamily="@string/font_family_regular"                 />         </linearlayout>     </relativelayout> </linearlayout> 

Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

dns - Dokku server hosts two sites with TLD's, both domains are landing on only one app -

Delphi 7 and decode UTF-8 base64 -