Android Java : Linear Layout vanishes when placed on another Linear Layout - java

I am working on the horizontal view for a basic Android calculator, and I have a LinearLayout called linearLayout2 that I am trying to place on top of linearLayout3, which contains the numbers 1, 2, 3, +, -, and (. The problem is that when I try to move linearLayout2 on top of linearLayout3, it immedietly vanishes to the top with 0 height.
Here is the XML code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:weightSum="1"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/linearLayout">
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/editText"
android:hint="#string/hint"
android:textSize="14dp"
android:background="#00000000" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/linearLayout3"
android:orientation="horizontal"
android:weightSum="1"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<Button
android:text="1"
android:layout_width="0dp"
android:layout_weight=".16667"
android:textAllCaps="false"
android:id="#+id/button37"
android:layout_height="wrap_content" />
<Button
android:text="2"
android:layout_width="0dp"
android:layout_weight=".16667"
android:textAllCaps="false"
android:id="#+id/button39"
android:layout_height="wrap_content" />
<Button
android:text="3"
android:layout_width="0dp"
android:layout_weight=".16667"
android:textAllCaps="false"
android:id="#+id/button40"
android:layout_height="wrap_content" />
<Button
android:text="+"
android:layout_width="0dp"
android:layout_weight=".16667"
android:textAllCaps="false"
android:id="#+id/button46"
android:layout_height="wrap_content" />
<Button
android:text="-"
android:layout_width="0dp"
android:layout_weight=".16667"
android:textAllCaps="false"
android:id="#+id/button47"
android:layout_height="wrap_content" />
<Button
android:text="("
android:layout_width="0dp"
android:layout_weight=".16667"
android:textAllCaps="false"
android:id="#+id/button49"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/linearLayout4"
android:orientation="horizontal"
android:weightSum="1"
android:layout_above="#+id/linearLayout5"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<Button
android:text="4"
android:layout_width="0dp"
android:layout_weight=".16667"
android:textAllCaps="false"
android:id="#+id/button41"
android:layout_height="wrap_content" />
<Button
android:text="5"
android:layout_width="0dp"
android:layout_weight=".16667"
android:textAllCaps="false"
android:id="#+id/button42"
android:layout_height="wrap_content" />
<Button
android:text="6"
android:layout_width="0dp"
android:layout_weight=".16667"
android:textAllCaps="false"
android:id="#+id/button43"
android:layout_height="wrap_content" />
<Button
android:text="*"
android:layout_width="0dp"
android:layout_weight=".16667"
android:textAllCaps="false"
android:id="#+id/button35"
android:layout_height="wrap_content" />
<Button
android:text="/"
android:layout_width="0dp"
android:layout_weight=".16667"
android:textAllCaps="false"
android:id="#+id/button36"
android:layout_height="wrap_content" />
<Button
android:text=")"
android:layout_width="0dp"
android:layout_weight=".16667"
android:textAllCaps="false"
android:id="#+id/button38"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/linearLayout5"
android:orientation="horizontal"
android:weightSum="1"
android:layout_above="#+id/linearLayout6"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<Button
android:text="7"
android:layout_width="0dp"
android:layout_weight=".16667"
android:textAllCaps="false"
android:id="#+id/button44"
android:layout_height="wrap_content" />
<Button
android:text="8"
android:layout_width="0dp"
android:layout_weight=".16667"
android:textAllCaps="false"
android:id="#+id/button45"
android:layout_height="wrap_content" />
<Button
android:text="9"
android:layout_width="0dp"
android:layout_weight=".16667"
android:textAllCaps="false"
android:id="#+id/button48"
android:layout_height="wrap_content" />
<Button
android:text="+/-"
android:layout_width="0dp"
android:layout_weight=".16667"
android:textAllCaps="false"
android:id="#+id/button50"
android:layout_height="wrap_content" />
<Button
android:text="%"
android:layout_width="0dp"
android:layout_weight=".16667"
android:textAllCaps="false"
android:id="#+id/button51"
android:layout_height="wrap_content" />
<Button
android:text="^"
android:layout_width="0dp"
android:layout_weight=".16667"
android:textAllCaps="false"
android:id="#+id/button52"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/linearLayout6"
android:orientation="horizontal"
android:weightSum="1"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
>
<Button
android:text="0"
android:layout_width="0dp"
android:layout_weight=".16667"
android:textAllCaps="false"
android:id="#+id/button25"
android:layout_height="wrap_content" />
<Button
android:text="."
android:layout_width="0dp"
android:layout_weight="0.3333"
android:textAllCaps="false"
android:id="#+id/button53"
android:layout_height="wrap_content" />
<Button
android:text="="
android:layout_width="0dp"
android:textAllCaps="false"
android:layout_weight="0.5"
android:id="#+id/button55"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/linearLayout2"
android:orientation="horizontal"
android:weightSum="1"
android:layout_above="#+id/linearLayout3"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
</LinearLayout>
<Button
android:text="Mode"
android:layout_width="0dp"
android:layout_weight="0.50"
android:textAllCaps="false"
android:id="#+id/button3"
android:background="#ffff5830"
android:layout_height="wrap_content"
android:layout_above="#+id/linearLayout3"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>

Try to use Gridlayout instead of LinearLayout if you want to develop a calculator.

Your Layout2 is using wrap_content for height
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/linearLayout2"
android:orientation="horizontal"
android:weightSum="1"
android:layout_above="#+id/linearLayout3"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
</LinearLayout>
but there is no content in that group (no child views) so this is correct behaviour as there is no need to make group height bigger.
Also, if you want to stack Layout2 on Layout3 you may consider wrapping themtogether in FrameLayout (or another RelativeLayout)

Related

How to fill a full line in a vertical LinearLayout

This is my first app so sorry I know its not that good. My english neither.
I got a problem with my xml design: I want 2 Buttons and 2 TextViews in one line and to fill the whole line. At the moment it looks like that:
but it gets even worse:
My code:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:text="-" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="#+id/textView11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<Button
android:id="#+id/button11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:text="+" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:text="-" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="#+id/textView12"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<Button
android:id="#+id/button12"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:text="+" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:text="-" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="#+id/textView13"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<Button
android:id="#+id/button13"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:text="+" />
</LinearLayout>
<!--
skipping additional rows of identical structure
-->
</LinearLayout>
The problem is that you use wrap_content on the children of the linear layout. there are 2 solutions to your problem one is to use match parent on the text views and add gravity centre to them like this:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:text="-" />
<TextView
android:id="#+id/textView3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="centre"
android:text="TextView" />
<TextView
android:id="#+id/textView13"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="centre"
android:text="TextView" />
<Button
android:id="#+id/button13"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:text="+" />
</LinearLayout>
And another solution is to use a constraint layout with allows you to spread the child views using chains.
If I understood correctly, you should try for each of your LinearLayout :
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="4" // number of sub items
>
<Button
android:id="#+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="-" />
<TextView
android:id="#+id/textView1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="TextView" />
<TextView
android:id="#+id/textView11"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="TextView" />
<Button
android:id="#+id/button11"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="+" />
Also, you should take a look at RecyclerViews and create your own adapter and rows. It will be much easier to deal with.

Create separator between button

I have problem with create my button separator. This my buttons layout with my xml layout my create button.
This is fragment activity_swipe.xml
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="#+id/searchDreamButton"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_weight="1"
android:background="#drawable/button_selector"
android:gravity="center"
android:text="#string/search_dream"
android:textAllCaps="false"
android:textColor="#color/colorWhite" />
<Button
android:id="#+id/singInButton"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_weight="1"
android:background="#drawable/button_selector"
android:gravity="center"
android:text="#string/sign_in"
android:textAllCaps="false"
android:textColor="#color/colorWhite" />
</LinearLayout>
but try make separator that this
Try this
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:gravity="center_vertical"
android:orientation="horizontal"
android:background="#android:color/holo_blue_bright"
>
<Button
android:id="#+id/searchDreamButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:background="#android:color/holo_blue_bright"
android:text="#string/search_dream"
android:textAllCaps="false"
/>
<View
android:layout_width="2dp"
android:layout_height="match_parent"
android:background="#color/black_color"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
/>
<Button
android:id="#+id/singInButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#android:color/holo_blue_bright"
android:gravity="center"
android:text="#string/sign_in"
android:textAllCaps="false"
/>
</LinearLayout>
try this my friend
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="#+id/searchDreamButton"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_weight="1"
android:background="#drawable/button_selector"
android:gravity="center"
android:text="#string/search_dream"
android:textAllCaps="false"
android:textColor="#color/colorWhite" />
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#000" />
<Button
android:id="#+id/singInButton"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_weight="1"
android:background="#drawable/button_selector"
android:gravity="center"
android:text="#string/sign_in"
android:textAllCaps="false"
android:textColor="#color/colorWhite" />
</LinearLayout>

Need help aligning buttons to bottom

Here is what it looks like currently:
http://i.stack.imgur.com/eaBpP.png
I want buttons to go and align at bottom (and cover all screen from sides too). I try to do this but getting unexpected results. Here is layout code:
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#000000" >
<GridLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:columnCount="3" >
<TextView
android:id="#+id/result"
android:layout_width="238dp"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_gravity="left"
android:layout_marginRight="40dp"
android:layout_row="0"
android:gravity="right"
android:text=""
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#FFFF00"
android:textSize="35sp"
android:textStyle="bold" />
<Space
android:layout_width="271dp"
android:layout_height="1dp"
android:layout_column="0"
android:layout_row="0" />
<ImageButton
android:id="#+id/clear"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_column="1"
android:layout_columnSpan="2"
android:layout_gravity="left"
android:layout_row="1"
android:layout_rowSpan="2"
android:paddingLeft="4dp"
android:src="#android:drawable/ic_input_delete" />
<Space
android:layout_width="12dp"
android:layout_height="15dp"
android:layout_column="2"
android:layout_row="1" />
<Space
android:layout_width="100dp"
android:layout_height="14dp"
android:layout_column="0"
android:layout_row="2" />
<Space
android:layout_width="100dp"
android:layout_height="13dp"
android:layout_row="2" />
</GridLayout>
<TableRow
android:id="#+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="30dp"
android:gravity="center" >
<Button
android:id="#+id/seven"
android:layout_width="80dp"
android:layout_height="100dp"
android:text="7"
android:textSize="50sp" />
<Button
android:id="#+id/eight"
android:layout_width="80dp"
android:layout_height="100dp"
android:text="8"
android:textSize="50sp" />
<Button
android:id="#+id/nine"
android:layout_width="80dp"
android:layout_height="100dp"
android:text="9"
android:textSize="50sp" />
<Button
android:id="#+id/divide"
style="#dimen/activity_horizontal_margin"
android:layout_width="80dp"
android:layout_height="100dp"
android:text="/"
android:textSize="50sp" />
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center" >
<Button
android:id="#+id/four"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:text="4"
android:textSize="50sp" />
<Button
android:id="#+id/five"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:text="5"
android:textSize="50sp" />
<Button
android:id="#+id/six"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:text="6"
android:textSize="50sp" />
<Button
android:id="#+id/multiply"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:text="x"
android:textSize="50sp" />
</TableRow>
<TableRow
android:id="#+id/tableRow9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center" >
<Button
android:id="#+id/one"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:text="1"
android:textSize="50sp" />
<Button
android:id="#+id/two"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:text="2"
android:textSize="50sp" />
<Button
android:id="#+id/three"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:text="3"
android:textSize="50sp" />
<Button
android:id="#+id/minus"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:text="-"
android:textSize="50sp" />
</TableRow>
<TableRow
android:id="#+id/tableRow14"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center" >
<Button
android:id="#+id/dot"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:text="."
android:textSize="50sp" />
<Button
android:id="#+id/zero"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:text="0"
android:textSize="50sp" />
<Button
android:id="#+id/equals"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:text="="
android:textSize="50sp" />
<Button
android:id="#+id/plus"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:text="+"
android:textSize="50sp" />
</TableRow>
</TableLayout>
Try this code to make the Numbers Grid covering the side spaces and the bottom space.Checkout if it is required o/p.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#000000" >
<GridLayout
android:id="#+id/grid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:columnCount="3" >
<TextView
android:id="#+id/result"
android:layout_width="238dp"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_gravity="left"
android:layout_marginRight="40dp"
android:layout_row="0"
android:gravity="right"
android:text=""
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#FFFF00"
android:textSize="35sp"
android:textStyle="bold" />
<Space
android:layout_width="271dp"
android:layout_height="1dp"
android:layout_column="0"
android:layout_row="0" />
<ImageButton
android:id="#+id/clear"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_column="1"
android:layout_columnSpan="2"
android:layout_gravity="left"
android:layout_row="1"
android:layout_rowSpan="2"
android:paddingLeft="4dp"
android:src="#android:drawable/ic_input_delete" />
<Space
android:layout_width="12dp"
android:layout_height="15dp"
android:layout_column="2"
android:layout_row="1" />
<Space
android:layout_width="100dp"
android:layout_height="14dp"
android:layout_column="0"
android:layout_row="2" />
<Space
android:layout_width="100dp"
android:layout_height="13dp"
android:layout_row="2" />
</GridLayout>
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_below="#id/grid"
android:gravity="bottom" >
<TableRow
android:id="#+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="30dp"
android:gravity="center" >
<Button
android:id="#+id/seven"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_weight="1"
android:text="7"
android:textSize="50sp" />
<Button
android:id="#+id/eight"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_weight="1"
android:text="8"
android:textSize="50sp" />
<Button
android:id="#+id/nine"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_weight="1"
android:text="9"
android:textSize="50sp" />
<Button
android:id="#+id/divide"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_weight="1"
android:text="/"
android:textSize="50sp" />
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center" >
<Button
android:id="#+id/four"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_weight="1"
android:text="4"
android:textSize="50sp" />
<Button
android:id="#+id/five"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_weight="1"
android:text="5"
android:textSize="50sp" />
<Button
android:id="#+id/six"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_weight="1"
android:text="6"
android:textSize="50sp" />
<Button
android:id="#+id/multiply"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_weight="1"
android:text="x"
android:textSize="50sp" />
</TableRow>
<TableRow
android:id="#+id/tableRow9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center" >
<Button
android:id="#+id/one"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_weight="1"
android:text="1"
android:textSize="50sp" />
<Button
android:id="#+id/two"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_weight="1"
android:text="2"
android:textSize="50sp" />
<Button
android:id="#+id/three"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_weight="1"
android:text="3"
android:textSize="50sp" />
<Button
android:id="#+id/minus"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_weight="1"
android:text="-"
android:textSize="50sp" />
</TableRow>
<TableRow
android:id="#+id/tableRow14"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center" >
<Button
android:id="#+id/dot"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_weight="1"
android:text="."
android:textSize="50sp" />
<Button
android:id="#+id/zero"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_weight="1"
android:text="0"
android:textSize="50sp" />
<Button
android:id="#+id/equals"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_weight="1"
android:text="="
android:textSize="50sp" />
<Button
android:id="#+id/plus"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_weight="1"
android:text="+"
android:textSize="50sp" />
</TableRow>
</TableLayout>
I add some sample code. Try to use this. It is just sample code....
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".Home" >
<EditText
android:id="#+id/display"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_gravity="center"
android:gravity="center"
android:orientation="horizontal"
android:paddingTop="20dp" >
<Button
android:id="#+id/seven"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:text="7"
/>
<Button
android:id="#+id/eight"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:text="8" />
<Button
android:id="#+id/nine"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:text="9" />
<Button
android:id="#+id/div"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:text="/" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_weight="1"
android:layout_gravity="center"
android:gravity="center"
android:orientation="horizontal"
android:paddingTop="20dp"
android:layout_height="0dp" >
<Button
android:id="#+id/four"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:text="4" />
<Button
android:id="#+id/five"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:text="5" />
<Button
android:id="#+id/six"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:text="6" />
<Button
android:id="#+id/mul"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:text="*" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_weight="1"
android:layout_gravity="center"
android:gravity="center"
android:orientation="horizontal"
android:paddingTop="20dp"
android:layout_height="0dp">
<Button
android:id="#+id/one"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:text="1" />
<Button
android:id="#+id/two"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:text="2" />
<Button
android:id="#+id/three"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:text="3" />
<Button
android:id="#+id/sub"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:text="-" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_weight="1"
android:layout_gravity="center"
android:gravity="center"
android:orientation="horizontal"
android:paddingTop="20dp"
android:layout_height="0dp">
<Button
android:id="#+id/cancel"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:text="c" />
<Button
android:id="#+id/zero"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:text="0" />
<Button
android:id="#+id/equal"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:text="=" />
<Button
android:id="#+id/add"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:text="+" />
</LinearLayout>
</LinearLayout>

Layout spacing issue in a bigger size screen

Does anyone know why this is happening:
The letters boxes are not aligned correctly in the tablet screen which is 10" but it works just fine on 7" and 4.7" screen.
Here is my XML layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:padding="5dp"
android:id="#+id/alphabetPad" >
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/rowABCD"
android:layout_weight="1">
<Button
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="#+id/btnA"
android:layout_weight="1"
android:text="A"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
<Button
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="#+id/btnB"
android:layout_weight="1"
android:text="B"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
<Button
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/btnC"
android:layout_weight="1"
android:text="C"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
<Button
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/btnD"
android:layout_weight="1"
android:text="D"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/rowEFGH"
android:layout_weight="1">
<Button
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="#+id/btnE"
android:layout_weight="1"
android:text="E"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
<Button
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="#+id/btnF"
android:layout_weight="1"
android:text="F"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
<Button
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="#+id/btnG"
android:layout_weight="1"
android:text="G"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
<Button
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="#+id/btnH"
android:layout_weight="1"
android:text="H"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:id="#+id/rowIJKL">
<Button
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="#+id/btnI"
android:layout_weight="1"
android:text="I"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
<Button
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="#+id/btnJ"
android:layout_weight="1"
android:text="J"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
<Button
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="#+id/btnK"
android:layout_weight="1"
android:text="K"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
<Button
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="#+id/btnL"
android:layout_weight="1"
android:text="L"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:id="#+id/rowMNOP">
<Button
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="#+id/btnM"
android:layout_weight="1"
android:text="M"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
<Button
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="#+id/btnN"
android:layout_weight="1"
android:text="N"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
<Button
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="#+id/btnO"
android:layout_weight="1"
android:text="O"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
<Button
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="#+id/btnP"
android:layout_weight="1"
android:text="P"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:id="#+id/rowQRST">
<Button
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="#+id/btnQ"
android:layout_weight="1"
android:text="Q"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
<Button
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="#+id/btnR"
android:layout_weight="1"
android:text="R"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
<Button
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="#+id/btnS"
android:layout_weight="1"
android:text="S"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
<Button
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="#+id/btnT"
android:layout_weight="1"
android:text="T"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:id="#+id/rowUVWX">
<Button
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="#+id/btnU"
android:layout_weight="1"
android:text="U"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
<Button
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="#+id/btnV"
android:layout_weight="1"
android:text="V"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
<Button
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="#+id/btnW"
android:layout_weight="1"
android:text="W"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
<Button
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/btnX"
android:layout_weight="1"
android:text="X"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:id="#+id/rowYZ">
<Button
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="#+id/btnBlank"
android:layout_weight="1"
android:text=""
android:visibility="invisible" />
<Button
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="#+id/btnY"
android:layout_weight="1"
android:text="Y"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
<Button
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="#+id/btnZ"
android:layout_weight="1"
android:text="Z"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
<Button
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/btnBlank"
android:layout_weight="1"
android:text=""
android:visibility="invisible" />
</LinearLayout>
</LinearLayout>
I am guessing the boxes are too big to fit. How can I make it so that no matter what screen size the app is being displayed on, the boxes always line up.
I tried changing the margin for each button, 1dp for larger screen and 2dp for smaller screen but that didn't help.
Help is greatly appreciated.
Just replace
android:layout_width = "wrap_content"
with
android:layout_width = "fill_parent"
Try the below layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:padding="5dp"
android:id="#+id/alphabetPad" >
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/rowABCD"
android:layout_weight="1">
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/btnA"
android:layout_weight="1"
android:text="A"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/btnB"
android:layout_weight="1"
android:text="B"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
<Button
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:id="#+id/btnC"
android:layout_weight="1"
android:text="C"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
<Button
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:id="#+id/btnD"
android:layout_weight="1"
android:text="D"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/rowEFGH"
android:layout_weight="1">
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/btnE"
android:layout_weight="1"
android:text="E"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/btnF"
android:layout_weight="1"
android:text="F"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/btnG"
android:layout_weight="1"
android:text="G"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/btnH"
android:layout_weight="1"
android:text="H"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:id="#+id/rowIJKL">
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/btnI"
android:layout_weight="1"
android:text="I"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/btnJ"
android:layout_weight="1"
android:text="J"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/btnK"
android:layout_weight="1"
android:text="K"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/btnL"
android:layout_weight="1"
android:text="L"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:id="#+id/rowMNOP">
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/btnM"
android:layout_weight="1"
android:text="M"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/btnN"
android:layout_weight="1"
android:text="N"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/btnO"
android:layout_weight="1"
android:text="O"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/btnP"
android:layout_weight="1"
android:text="P"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:id="#+id/rowQRST">
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/btnQ"
android:layout_weight="1"
android:text="Q"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/btnR"
android:layout_weight="1"
android:text="R"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/btnS"
android:layout_weight="1"
android:text="S"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/btnT"
android:layout_weight="1"
android:text="T"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:id="#+id/rowUVWX">
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/btnU"
android:layout_weight="1"
android:text="U"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/btnV"
android:layout_weight="1"
android:text="V"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/btnW"
android:layout_weight="1"
android:text="W"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
<Button
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:id="#+id/btnX"
android:layout_weight="1"
android:text="X"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:id="#+id/rowYZ">
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/btnBlank"
android:layout_weight="1"
android:text=""
android:visibility="invisible" />
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/btnY"
android:layout_weight="1"
android:text="Y"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/btnZ"
android:layout_weight="1"
android:text="Z"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
<Button
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:id="#+id/btnBlank"
android:layout_weight="1"
android:text=""
android:visibility="invisible" />
</LinearLayout>
Please check the modified layout I just posted in my answer. It is working fine for me when I tested. When you are specifying layout_weight in a linear layout, it is always better to use layout_width or layout_height as fill_parent, as the LinearLayout adjusts the layout according to the layout_weight attribute, regardless of the content inside the layout.
Let me know if it works for you too!
You can use TableLayout with android:stretchColumns="*" to force all columns to have the exact same width.
Example
<?xml version="1.0" encoding="utf-8"?>
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:padding="5dp"
android:stretchColumns="*" >
<TableRow android:layout_weight="1">
<Button android:text="A"
android:layout_height="match_parent"/>
<Button android:text="B"
android:layout_height="match_parent"/>
<Button android:text="C"
android:layout_height="match_parent"/>
<Button android:text="D"
android:layout_height="match_parent"/>
<Button android:text="E"
android:layout_height="match_parent"/>
</TableRow>
<TableRow android:layout_weight="1">
<Button android:text="F"
android:layout_height="match_parent"/>
<Button android:text="G"
android:layout_height="match_parent"/>
<Button android:text="H"
android:layout_height="match_parent"/>
<Button android:text="I"
android:layout_height="match_parent"/>
<Button android:text="J"
android:layout_height="match_parent"/>
</TableRow>
<TableRow android:layout_weight="1">
<Button android:text="K"
android:layout_height="match_parent"/>
<Button android:text="L"
android:layout_height="match_parent"/>
<Button android:text="M"
android:layout_height="match_parent"/>
<Button android:text="N"
android:layout_height="match_parent"/>
<Button android:text="O"
android:layout_height="match_parent"/>
</TableRow>
<TableRow android:layout_weight="1">
<Button android:text="P"
android:layout_height="match_parent"/>
<Button android:text="Q"
android:layout_height="match_parent"/>
<Button android:text="R"
android:layout_height="match_parent"/>
<Button android:text="S"
android:layout_height="match_parent"/>
<Button android:text="T"
android:layout_height="match_parent"/>
</TableRow>
</TableLayout>

Landscape mode: why do I get different result on my computer screen and different on my phone?

This is the first time I'm making an activity xml in landscape model. Until now, what I saw on my computer screen that was what I got on my phone. Now, it's not even close! I placed some layouts, buttons and stuff, centered them like I need them, and tried on the phone and some stuff are way off the screen, some stuff are moved to the right, nothing is like I made it in my xml. So I have to move some stuff a little, then try it on my phone, without any order or rule. Why is this happening?
<?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"
android:background="#drawable/backgroundland" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="4" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1" >
<Button
android:id="#+id/bA1"
android:layout_width="115dp"
android:background="#drawable/buttons"
android:textSize="18sp"
android:textColor="#ffffff"
android:padding="0dp"
android:layout_margin="3dp"
android:layout_height="35dp"
android:text="A1" />
<Button
android:id="#+id/bA2"
android:layout_width="115dp"
android:background="#drawable/buttons"
android:textSize="18sp"
android:textColor="#ffffff"
android:padding="0dp"
android:layout_margin="3dp"
android:layout_height="35dp"
android:text="A2" />
<Button
android:id="#+id/bA3"
android:layout_width="115dp"
android:background="#drawable/buttons"
android:textSize="18sp"
android:textColor="#ffffff"
android:padding="0dp"
android:layout_margin="3dp"
android:layout_height="35dp"
android:text="A3" />
<Button
android:id="#+id/bA4"
android:layout_width="115dp"
android:background="#drawable/buttons"
android:textSize="18sp"
android:textColor="#ffffff"
android:padding="0dp"
android:layout_margin="3dp"
android:layout_height="35dp"
android:text="A4" />
<Button
android:id="#+id/bKolonaA"
android:layout_width="115dp"
android:background="#drawable/buttons"
android:textSize="19sp"
android:textColor="#ffffff"
android:padding="0dp"
android:layout_margin="3dp"
android:layout_height="35dp"
android:text="Kolona A" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="1" >
<Button
android:id="#+id/bB1"
android:layout_width="115dp"
android:background="#drawable/buttons"
android:textSize="18sp"
android:textColor="#ffffff"
android:padding="0dp"
android:layout_margin="3dp"
android:layout_height="35dp"
android:text="B1" />
<Button
android:id="#+id/bB2"
android:layout_width="115dp"
android:background="#drawable/buttons"
android:textSize="18sp"
android:textColor="#ffffff"
android:padding="0dp"
android:layout_margin="3dp"
android:layout_height="35dp"
android:text="B2" />
<Button
android:id="#+id/bB3"
android:layout_width="115dp"
android:background="#drawable/buttons"
android:textSize="18sp"
android:textColor="#ffffff"
android:padding="0dp"
android:layout_margin="3dp"
android:layout_height="35dp"
android:text="B3" />
<Button
android:id="#+id/bB4"
android:layout_width="115dp"
android:background="#drawable/buttons"
android:textSize="18sp"
android:textColor="#ffffff"
android:padding="0dp"
android:layout_margin="3dp"
android:layout_height="35dp"
android:text="B4" />
<Button
android:id="#+id/bKolonaB"
android:layout_width="115dp"
android:background="#drawable/buttons"
android:textSize="19sp"
android:textColor="#ffffff"
android:padding="0dp"
android:layout_margin="3dp"
android:layout_height="35dp"
android:text="Kolona B" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1" >
<Button
android:id="#+id/bC1"
android:layout_width="115dp"
android:background="#drawable/buttons"
android:textSize="18sp"
android:textColor="#ffffff"
android:padding="0dp"
android:layout_margin="3dp"
android:layout_height="35dp"
android:text="C1" />
<Button
android:id="#+id/bC2"
android:layout_width="115dp"
android:background="#drawable/buttons"
android:textSize="18sp"
android:textColor="#ffffff"
android:padding="0dp"
android:layout_margin="3dp"
android:layout_height="35dp"
android:text="C2" />
<Button
android:id="#+id/bC3"
android:layout_width="115dp"
android:background="#drawable/buttons"
android:textSize="18sp"
android:textColor="#ffffff"
android:padding="0dp"
android:layout_margin="3dp"
android:layout_height="35dp"
android:text="C3" />
<Button
android:id="#+id/bC4"
android:layout_width="115dp"
android:layout_height="35dp"
android:layout_margin="3dp"
android:background="#drawable/buttons"
android:padding="0dp"
android:text="C4"
android:textColor="#ffffff"
android:textSize="18sp" />
<Button
android:id="#+id/bKolonaC"
android:layout_width="115dp"
android:background="#drawable/buttons"
android:textSize="19sp"
android:textColor="#ffffff"
android:padding="0dp"
android:layout_margin="3dp"
android:layout_height="35dp"
android:text="Kolona C" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1" >
<Button
android:id="#+id/bD1"
android:layout_width="115dp"
android:background="#drawable/buttons"
android:textSize="18sp"
android:textColor="#ffffff"
android:padding="0dp"
android:layout_margin="3dp"
android:layout_height="35dp"
android:text="D1" />
<Button
android:id="#+id/bD2"
android:layout_width="115dp"
android:background="#drawable/buttons"
android:textSize="18sp"
android:textColor="#ffffff"
android:padding="0dp"
android:layout_margin="3dp"
android:layout_height="35dp"
android:text="D2" />
<Button
android:id="#+id/bD3"
android:layout_width="115dp"
android:background="#drawable/buttons"
android:textSize="18sp"
android:textColor="#ffffff"
android:padding="0dp"
android:layout_margin="3dp"
android:layout_height="35dp"
android:text="D3" />
<Button
android:id="#+id/bD4"
android:layout_width="115dp"
android:background="#drawable/buttons"
android:textSize="18sp"
android:textColor="#ffffff"
android:padding="0dp"
android:layout_margin="3dp"
android:layout_height="35dp"
android:text="D4" />
<Button
android:id="#+id/bKolonaD"
android:layout_width="115dp"
android:background="#drawable/buttons"
android:textSize="19sp"
android:textColor="#ffffff"
android:padding="0dp"
android:layout_margin="3dp"
android:layout_height="35dp"
android:text="Kolona D" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="120dp"
android:layout_height="wrap_content" >
<Button
android:id="#+id/bIzlazA"
android:layout_width="50dp"
android:layout_height="35dp"
android:layout_marginLeft="20dp"
android:layout_marginTop="3dp"
android:background="#drawable/buttons_final"
android:padding="0dp"
android:text=""
android:textColor="#ffffff"
android:textSize="20sp" />
</LinearLayout>
<LinearLayout
android:layout_width="280dp"
android:layout_height="wrap_content" >
<Button
android:id="#+id/bKonacno"
android:layout_width="260dp"
android:layout_height="35dp"
android:layout_marginTop="3dp"
android:background="#drawable/buttons_final"
android:padding="0dp"
android:text=""
android:textColor="#ffffff"
android:textSize="20sp" />
</LinearLayout>
<LinearLayout
android:layout_width="100dp"
android:layout_height="match_parent" >
<TextView
android:id="#+id/tvVreme"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginTop="8dp"
android:text="100"
android:textColor="#ff0000"
android:textSize="20sp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
what i know is that the emulator doesn't work same as real devices so why don't you us your phone in debug mode to see what your code really do.
post your code may be we can see if it's not the emulator problem
EDIT:
just add android:layoutweight="1" to the 3 lyouts at the bottom
you should have better results :)
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="120dp"
android:layout_weight="1"
android:layout_height="wrap_content" >
<Button
android:id="#+id/bIzlazA"
android:layout_width="50dp"
android:layout_height="35dp"
android:layout_marginLeft="20dp"
android:layout_marginTop="3dp"
android:background="#drawable/ic_launcher"
android:padding="0dp"
android:text=""
android:textColor="#ffffff"
android:textSize="20sp" />
</LinearLayout>
<LinearLayout
android:layout_width="280dp"
android:layout_weight="1"
android:layout_height="wrap_content" >
<Button
android:id="#+id/bKonacno"
android:layout_width="260dp"
android:layout_height="35dp"
android:layout_marginTop="3dp"
android:background="#drawable/ic_launcher"
android:padding="0dp"
android:textColor="#ffffff"
android:textSize="20sp" />
</LinearLayout>
<LinearLayout
android:layout_width="100dp"
android:layout_weight="1"
android:layout_height="match_parent" >
<TextView
android:id="#+id/tvVreme"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginTop="8dp"
android:text="100"
android:textColor="#ff0000"
android:textSize="20sp" />
</LinearLayout>
</LinearLayout>
Probably different resolutions on emulator and on device, and you didn't used dpi but pixels.
Also it can be a problem when using absolute layout.
Hard to gues without the code

Categories

Resources