android - Troubles positioning layouts to tic tac toe app - falling off screen -


i new android development. took begginer course in udacity last month. i'm having troubles positioning layouts cause there not shown ot screen , on diferent devices looking different altough im not using particular dimentions @ all. tic-tac-toe game, used buttons 9 fields crosses , circles. i've tried these layouts , need cause have ready project till 11th of july. thank you. here whole code because think problem can't solved otherwise.

this how displayed on screen of google nexus s 4.1.1 api 16 480x800, 240dpi

    <relativelayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     android:theme="@style/purpletheme"     android:background="@drawable/background_1a"     tools:context="com.example.android.tictactoe.mainactivity"     android:layout_width="fill_parent"     android:layout_height="fill_parent"     android:weightsum="7">  <linearlayout     android:id="@+id/general_layout"     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:layout_centerhorizontal="true"     android:orientation="vertical"     android:weightsum="6">      <imageview         android:id="@+id/logo"         android:layout_width="match_parent"         android:layout_height="0dp"         android:layout_weight="1"         android:layout_margin="5dp"         android:src="@drawable/logo_white"/>      <!-- up-->     <linearlayout         android:layout_gravity="center"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:layout_weight="3"         android:weightsum="3"         android:orientation="vertical"         android:layout_marginleft="16dp"         android:layout_marginright="16dp">          <linearlayout             android:layout_width="match_parent"             android:layout_height="match_parent"             android:orientation="horizontal"             android:layout_weight="1"             android:weightsum="3">              <button                 android:id="@+id/top_left_btn"                 android:layout_width="0dp"                 android:layout_height="match_parent"                 android:layout_margin="1dp"                 android:layout_marginbottom="1dp"                 android:layout_marginleft="1dp"                 android:layout_marginright="1dp"                 android:layout_margintop="1dp"                 android:enabled="true"                 android:textcolor="#5d178f"                 android:textcolorhighlight="#f1c918"                 android:textsize="64sp"                 android:layout_weight="1" />              <button                 android:id="@+id/top_centre_btn"                 android:layout_width="0dp"                 android:layout_height="match_parent"                 android:layout_margin="1dp"                 android:layout_marginbottom="1dp"                 android:layout_marginleft="1dp"                 android:layout_marginright="1dp"                 android:layout_margintop="1dp"                 android:enabled="true"                 android:textcolor="#5d178f"                 android:textcolorhighlight="#f1c918"                 android:textsize="64sp"                 android:layout_weight="1" />              <button                 android:id="@+id/top_right_btn"                 android:layout_width="0dp"                 android:layout_height="match_parent"                 android:layout_margin="1dp"                 android:layout_marginbottom="1dp"                 android:layout_marginleft="1dp"                 android:layout_marginright="1dp"                 android:layout_margintop="1dp"                 android:enabled="true"                 android:textcolor="#5d178f"                 android:textcolorhighlight="#f1c918"                 android:textsize="64sp"                 android:layout_weight="1" />          </linearlayout>          <linearlayout             android:layout_width="match_parent"             android:layout_height="match_parent"             android:orientation="horizontal"             android:layout_weight="1"             android:weightsum="3">              <button                 android:id="@+id/middle_left_btn"                 android:layout_width="0dp"                 android:layout_height="match_parent"                 android:layout_margin="1dp"                 android:layout_marginbottom="1dp"                 android:layout_marginleft="1dp"                 android:layout_marginright="1dp"                 android:layout_margintop="1dp"                 android:enabled="true"                 android:textcolor="#5d178f"                 android:textcolorhighlight="#f1c918"                 android:textsize="64sp"                 android:layout_weight="1" />              <button                 android:id="@+id/middle_centre_btn"                 android:layout_width="0dp"                 android:layout_height="match_parent"                 android:layout_margin="1dp"                 android:layout_marginbottom="1dp"                 android:layout_marginleft="1dp"                 android:layout_marginright="1dp"                 android:layout_margintop="1dp"                 android:enabled="true"                 android:textcolor="#5d178f"                 android:textcolorhighlight="#f1c918"                 android:textsize="64sp"                 android:layout_weight="1" />              <button                 android:id="@+id/middle_right_btn"                 android:layout_width="0dp"                 android:layout_height="match_parent"                 android:layout_margin="1dp"                 android:layout_marginbottom="1dp"                 android:layout_marginleft="1dp"                 android:layout_marginright="1dp"                 android:layout_margintop="1dp"                 android:enabled="true"                 android:textcolor="#5d178f"                 android:textcolorhighlight="#f1c918"                 android:textsize="64sp"                 android:layout_weight="1" />         </linearlayout>          <linearlayout             android:layout_width="match_parent"             android:layout_height="match_parent"             android:orientation="horizontal"             android:layout_weight="1"             android:weightsum="3">              <button                 android:id="@+id/bottom_left_btn"                 android:layout_width="0dp"                 android:layout_height="match_parent"                 android:layout_margin="1dp"                 android:layout_marginbottom="1dp"                 android:layout_marginleft="1dp"                 android:layout_marginright="1dp"                 android:layout_margintop="1dp"                 android:enabled="true"                 android:textcolor="#5d178f"                 android:textcolorhighlight="#f1c918"                 android:textsize="64sp"                 android:layout_weight="1" />              <button                 android:id="@+id/bottom_centre_btn"                 android:layout_width="0dp"                 android:layout_height="match_parent"                 android:layout_margin="1dp"                 android:layout_marginbottom="1dp"                 android:layout_marginleft="1dp"                 android:layout_marginright="1dp"                 android:layout_margintop="1dp"                 android:enabled="true"                 android:textcolor="#5d178f"                 android:textcolorhighlight="#f1c918"                 android:textsize="64sp"                 android:layout_weight="1" />              <button                 android:id="@+id/bottom_right_btn"                 android:layout_width="0dp"                 android:layout_height="match_parent"                 android:layout_margin="1dp"                 android:layout_marginbottom="1dp"                 android:layout_marginleft="1dp"                 android:layout_marginright="1dp"                 android:layout_margintop="1dp"                 android:enabled="true"                 android:textcolor="#5d178f"                 android:textcolorhighlight="#f1c918"                 android:textsize="64sp"                 android:layout_weight="1" />         </linearlayout>      </linearlayout>      <linearlayout         android:layout_width="match_parent"         android:layout_height="0dp"         android:layout_weight="2"         android:weightsum="2"         android:orientation="horizontal">          <!-- player x-->     <linearlayout         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:orientation="vertical"         android:layout_weight="1">          <edittext                 android:layout_width="match_parent"                 android:layout_height="wrap_content"                 android:textcolor="#ffffff"                 android:gravity="center_horizontal"                 android:id="@+id/nameofplayerx"                 android:paddingtop="0dp"                 android:textsize="22sp"                 android:fontfamily="sans-serif-light"                 android:textisselectable="false"                 android:hint="player x"                 android:textcolorhint="#ffffff"                 android:inputtype="textfilter"                 android:maxlength="15"                 />         <textview             android:id="@+id/player_x_score"             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:gravity="center_horizontal"             android:textsize="56sp"             android:textcolor="#ffffff"             android:fontfamily="sans-serif-light"             android:text="0" />      </linearlayout>          <view             android:layout_width="1dp"             android:layout_height="match_parent"             android:background="@android:color/darker_gray"             android:layout_centerinparent="true"/>          <!-- player o-->         <linearlayout             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:layout_weight="1"             android:orientation="vertical">              <edittext                 android:layout_width="match_parent"                 android:layout_height="wrap_content"                 android:fontfamily="sans-serif-light"                 android:gravity="center_horizontal"                 android:textcolor="#ffffff"                 android:id="@+id/nameofplayero"                 android:paddingtop="0dp"                 android:textsize="22sp"                 android:hint="player o"                 android:textcolorhint="#ffffff"                 android:inputtype="textfilter"                 android:maxlength="15"                 />             <textview                 android:id="@+id/player_o_score"                 android:layout_width="match_parent"                 android:layout_height="wrap_content"                 android:gravity="center_horizontal"                 android:layout_marginbottom="0dp"                 android:layout_margintop="0dp"                 android:textsize="56sp"                 android:textcolor="#ffffff"                 android:fontfamily="sans-serif-light"                 android:text="0" />          </linearlayout>     </linearlayout>  </linearlayout>     <button         style="?android:attr/buttonstylesmall"         android:layout_width="wrap_content"         android:layout_weight="1"         android:layout_height="0dp"         android:text="reset score"         android:id="@+id/reset_btn"         android:layout_gravity="center_horizontal"         android:longclickable="true"         android:onclick="reset"         android:layout_alignparentbottom="true"         />     <!-- not sure longclicable -->     <!--end of bottom part players' names , score --> </relativelayout> 

if want distribute layouts evenly weights parent has linearlayout, weights don't work relativelayout. i've made necessary changes in layout spaced evenly. please have closer on how weights distributed. hope helps. try out kdeogharkar's answer because more efficient nested weights bad performance.

<linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     android:orientation="vertical"     android:theme="@style/purpletheme"     android:background="@drawable/background_1a"     tools:context="com.example.android.tictactoe.mainactivity"     android:layout_width="fill_parent"     android:layout_height="fill_parent">      <linearlayout         android:id="@+id/general_layout"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:layout_centerhorizontal="true"         android:layout_centerinparent="true"         android:layout_weight="1"         android:orientation="vertical"         android:weightsum="6">          <imageview             android:id="@+id/logo"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:layout_weight="1"             android:layout_margin="5dp"             android:layout_gravity="center"             android:src="@drawable/logo_white"/>          <!-- up-->         <linearlayout             android:layout_gravity="center"             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:layout_weight="3"             android:weightsum="3"             android:orientation="vertical"             android:gravity="center"             android:layout_marginleft="16dp"             android:layout_marginright="16dp">              <linearlayout                 android:layout_width="match_parent"                 android:layout_height="match_parent"                 android:orientation="horizontal"                 android:layout_weight="1"                 android:weightsum="3">                  <button                     android:id="@+id/top_left_btn"                     android:layout_width="0dp"                     android:layout_height="match_parent"                     android:layout_margin="1dp"                     android:layout_marginbottom="1dp"                     android:layout_marginleft="1dp"                     android:layout_marginright="1dp"                     android:layout_margintop="1dp"                     android:enabled="true"                     android:textcolor="#5d178f"                     android:textcolorhighlight="#f1c918"                     android:textsize="64sp"                     android:layout_weight="1" />                  <button                     android:id="@+id/top_centre_btn"                     android:layout_width="0dp"                     android:layout_height="match_parent"                     android:layout_margin="1dp"                     android:layout_marginbottom="1dp"                     android:layout_marginleft="1dp"                     android:layout_marginright="1dp"                     android:layout_margintop="1dp"                     android:enabled="true"                     android:textcolor="#5d178f"                     android:textcolorhighlight="#f1c918"                     android:textsize="64sp"                     android:layout_weight="1" />                  <button                     android:id="@+id/top_right_btn"                     android:layout_width="0dp"                     android:layout_height="match_parent"                     android:layout_margin="1dp"                     android:layout_marginbottom="1dp"                     android:layout_marginleft="1dp"                     android:layout_marginright="1dp"                     android:layout_margintop="1dp"                     android:enabled="true"                     android:textcolor="#5d178f"                     android:textcolorhighlight="#f1c918"                     android:textsize="64sp"                     android:layout_weight="1" />              </linearlayout>              <linearlayout                 android:layout_width="match_parent"                 android:layout_height="match_parent"                 android:orientation="horizontal"                 android:layout_weight="1"                 android:weightsum="3">                  <button                     android:id="@+id/middle_left_btn"                     android:layout_width="0dp"                     android:layout_height="match_parent"                     android:layout_margin="1dp"                     android:layout_marginbottom="1dp"                     android:layout_marginleft="1dp"                     android:layout_marginright="1dp"                     android:layout_margintop="1dp"                     android:enabled="true"                     android:textcolor="#5d178f"                     android:textcolorhighlight="#f1c918"                     android:textsize="64sp"                     android:layout_weight="1" />                  <button                     android:id="@+id/middle_centre_btn"                     android:layout_width="0dp"                     android:layout_height="match_parent"                     android:layout_margin="1dp"                     android:layout_marginbottom="1dp"                     android:layout_marginleft="1dp"                     android:layout_marginright="1dp"                     android:layout_margintop="1dp"                     android:enabled="true"                     android:textcolor="#5d178f"                     android:textcolorhighlight="#f1c918"                     android:textsize="64sp"                     android:layout_weight="1" />                  <button                     android:id="@+id/middle_right_btn"                     android:layout_width="0dp"                     android:layout_height="match_parent"                     android:layout_margin="1dp"                     android:layout_marginbottom="1dp"                     android:layout_marginleft="1dp"                     android:layout_marginright="1dp"                     android:layout_margintop="1dp"                     android:enabled="true"                     android:textcolor="#5d178f"                     android:textcolorhighlight="#f1c918"                     android:textsize="64sp"                     android:layout_weight="1" />             </linearlayout>              <linearlayout                 android:layout_width="match_parent"                 android:layout_height="match_parent"                 android:orientation="horizontal"                 android:layout_weight="1"                 android:weightsum="3">                  <button                     android:id="@+id/bottom_left_btn"                     android:layout_width="0dp"                     android:layout_height="match_parent"                     android:layout_margin="1dp"                     android:layout_marginbottom="1dp"                     android:layout_marginleft="1dp"                     android:layout_marginright="1dp"                     android:layout_margintop="1dp"                     android:enabled="true"                     android:textcolor="#5d178f"                     android:textcolorhighlight="#f1c918"                     android:textsize="64sp"                     android:layout_weight="1" />                  <button                     android:id="@+id/bottom_centre_btn"                     android:layout_width="0dp"                     android:layout_height="match_parent"                     android:layout_margin="1dp"                     android:layout_marginbottom="1dp"                     android:layout_marginleft="1dp"                     android:layout_marginright="1dp"                     android:layout_margintop="1dp"                     android:enabled="true"                     android:textcolor="#5d178f"                     android:textcolorhighlight="#f1c918"                     android:textsize="64sp"                     android:layout_weight="1" />                  <button                     android:id="@+id/bottom_right_btn"                     android:layout_width="0dp"                     android:layout_height="match_parent"                     android:layout_margin="1dp"                     android:layout_marginbottom="1dp"                     android:layout_marginleft="1dp"                     android:layout_marginright="1dp"                     android:layout_margintop="1dp"                     android:enabled="true"                     android:textcolor="#5d178f"                     android:textcolorhighlight="#f1c918"                     android:textsize="64sp"                     android:layout_weight="1" />             </linearlayout>          </linearlayout>        </linearlayout>     <linearlayout         android:id="@+id/players_scoreboard"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:layout_weight="1"         android:weightsum="2"         android:layout_above="@+id/reset_btn"         android:orientation="horizontal">          <!-- player x-->         <linearlayout             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:orientation="vertical"             android:layout_weight="1">              <edittext                 android:layout_width="match_parent"                 android:layout_height="wrap_content"                 android:textcolor="#ffffff"                 android:gravity="center_horizontal"                 android:id="@+id/nameofplayerx"                 android:paddingtop="0dp"                 android:textsize="22sp"                 android:fontfamily="sans-serif-light"                 android:textisselectable="false"                 android:hint="player x"                 android:textcolorhint="#ffffff"                 android:inputtype="textfilter"                 android:maxlength="15"                 />             <textview                 android:id="@+id/player_x_score"                 android:layout_width="match_parent"                 android:layout_height="wrap_content"                 android:gravity="center_horizontal"                 android:textsize="56sp"                 android:textcolor="#ffffff"                 android:fontfamily="sans-serif-light"                 android:text="0" />          </linearlayout>          <view             android:layout_width="1dp"             android:layout_height="match_parent"             android:background="@android:color/darker_gray"             android:layout_centerinparent="true"/>          <!-- player o-->         <linearlayout             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:layout_weight="1"             android:orientation="vertical">              <edittext                 android:layout_width="match_parent"                 android:layout_height="wrap_content"                 android:fontfamily="sans-serif-light"                 android:gravity="center_horizontal"                 android:textcolor="#ffffff"                 android:id="@+id/nameofplayero"                 android:paddingtop="0dp"                 android:textsize="22sp"                 android:hint="player o"                 android:textcolorhint="#ffffff"                 android:inputtype="textfilter"                 android:maxlength="15"                 />             <textview                 android:id="@+id/player_o_score"                 android:layout_width="match_parent"                 android:layout_height="wrap_content"                 android:gravity="center_horizontal"                 android:layout_marginbottom="0dp"                 android:layout_margintop="0dp"                 android:textsize="56sp"                 android:textcolor="#ffffff"                 android:fontfamily="sans-serif-light"                 android:text="0" />          </linearlayout>      </linearlayout>     <button         style="?android:attr/buttonstylesmall"         android:layout_width="wrap_content"         android:layout_weight="1"         android:layout_height="0dp"         android:text="reset score"         android:id="@+id/reset_btn"         android:layout_gravity="center"         android:layout_alignparentbottom="true"         android:layout_centerhorizontal="true"         android:longclickable="true"         android:onclick="reset" />     <!-- not sure longclicable -->     <!--end of bottom part players' names , score --> </linearlayout> 

Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -