android - How to center linearlayout with 6 buttons on the center on portrait and landscape orientation? -


what want achieve: center layout both orientation.

    <scrollview     android:layout_height="match_parent"     android:layout_width="match_parent"     xmlns:android="http://schemas.android.com/apk/res/android"     android:background="#fffffce0"> <relativelayout     android:layout_width="match_parent"     android:layout_height="match_parent"     xmlns:android="http://schemas.android.com/apk/res/android"     android:background="#fffffce0"     android:weightsum="1">       <linearlayout         android:orientation="horizontal"         android:layout_width="match_parent"         android:layout_height="121dp"         android:background="#fffffce0"         android:layout_margintop="42dp"         android:id="@+id/linearlayout"         android:gravity="center_horizontal"         android:layout_alignparenttop="true"         android:layout_alignparentleft="true"         android:layout_alignparentstart="true">          <button             android:layout_width="120dp"             android:layout_height="120dp"             android:id="@+id/button9"             android:background="@drawable/custom_button_square"             android:text="@string/a_d"             android:textcolor="#ffff"             android:textsize="35sp"             android:onclick="gotoad"/>          <button             android:layout_width="120dp"             android:layout_height="120dp"             android:id="@+id/button10"             android:background="@drawable/custom_button_square"             android:text="@string/e_h"             android:textcolor="#ffff"             android:textsize="35sp" />     </linearlayout>      <linearlayout         android:orientation="horizontal"         android:layout_width="match_parent"         android:layout_height="120dp"         android:layout_below="@+id/linearlayout"         android:layout_centerhorizontal="true"         android:gravity="center_horizontal"         android:background="#fffffce0"         android:id="@+id/linearlayout2">          <button             android:layout_width="120dp"             android:layout_height="120dp"             android:id="@+id/button11"             android:background="@drawable/custom_button_square"             android:text="@string/i_l"             android:textcolor="#ffff"             android:textsize="35sp" />          <button             android:layout_width="120dp"             android:layout_height="120dp"             android:id="@+id/button12"             android:background="@drawable/custom_button_square"             android:text="@string/m_p"             android:textcolor="#ffff"             android:textsize="35sp" />     </linearlayout>      <linearlayout         android:orientation="horizontal"         android:layout_width="match_parent"         android:layout_height="120dp"         android:layout_below="@+id/linearlayout2"         android:layout_centerhorizontal="true"         android:background="#fffffce0"         android:gravity="center_horizontal">          <button             android:layout_width="120dp"             android:layout_height="120dp"             android:id="@+id/button13"             android:background="@drawable/custom_button_square"             android:text="@string/m_p"             android:textcolor="#ffff"             android:textsize="35sp" />          <button             android:layout_width="120dp"             android:layout_height="120dp"             android:id="@+id/button14"             android:background="@drawable/custom_button_square"             android:text="@string/q_t"             android:textcolor="#ffff"             android:textsize="35sp" />     </linearlayout>  </relativelayout> 

problem: ok, until moment tested app on tablet bigger screen. when orientation landscape, everyting ok, when rotate screen, looks that: http://zapodaj.net/b2780f7e637ab.png.html

i tried set gravity llayout center, didnt work.

well ! this. try this..

<scrollview xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#fffffce0" >  <linearlayout     android:layout_width="match_parent"     android:layout_height="match_parent"     android:background="#fffffce0"     android:gravity="center"     android:layout_gravity="center"     android:orientation="vertical"     android:weightsum="1" >      <linearlayout         android:id="@+id/linearlayout"         android:layout_width="match_parent"         android:layout_height="121dp"         android:layout_margintop="42dp"         android:background="#fffffce0"         android:gravity="center_horizontal"         android:orientation="horizontal" >          <button             android:id="@+id/button9"             android:layout_width="120dp"             android:layout_height="120dp"             android:background="@drawable/ic_launcher"             android:onclick="gotoad"             android:text="a_d"             android:textcolor="#ffff"             android:textsize="35sp" />          <button             android:id="@+id/button10"             android:layout_width="120dp"             android:layout_height="120dp"             android:background="@drawable/ic_launcher"             android:text="e_h"             android:textcolor="#ffff"             android:textsize="35sp" />     </linearlayout>      <linearlayout         android:id="@+id/linearlayout2"         android:layout_width="match_parent"         android:layout_height="120dp"         android:background="#fffffce0"         android:gravity="center_horizontal"         android:orientation="horizontal" >          <button             android:id="@+id/button11"             android:layout_width="120dp"             android:layout_height="120dp"             android:background="@drawable/ic_launcher"             android:text="i_l"             android:textcolor="#ffff"             android:textsize="35sp" />          <button             android:id="@+id/button12"             android:layout_width="120dp"             android:layout_height="120dp"             android:background="@drawable/ic_launcher"             android:text="m_p"             android:textcolor="#ffff"             android:textsize="35sp" />     </linearlayout>      <linearlayout         android:layout_width="match_parent"         android:layout_height="120dp"         android:background="#fffffce0"         android:gravity="center_horizontal"         android:orientation="horizontal" >          <button             android:id="@+id/button13"             android:layout_width="120dp"             android:layout_height="120dp"             android:background="@drawable/ic_launcher"             android:text="m_p"             android:textcolor="#ffff"             android:textsize="35sp" />          <button             android:id="@+id/button14"             android:layout_width="120dp"             android:layout_height="120dp"             android:background="@drawable/ic_launcher"             android:text="q_t"             android:textcolor="#ffff"             android:textsize="35sp" />     </linearlayout> </linearlayout> 


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -