• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Weird layout on phone

YoungDON

Lurker
Hey guys. So, I started learning android development recently, and after a week, I've gotten far enough to create a simple calculator. I have two problems with the layout.
  1. I wish to remove the toolbar. I tried to change the theme to one without a toolbar (NoActionBar). This works in the design view, but doesn't reflect in the emulator (AVD) or my phone.
  2. The second and more bothersome problem is with the buttons. I used a GridLayout for a 5x4 button grid, and I use the layout_columnWeight and layout_rowWeight to ensure they are the same size across the screen. It appears nice in the design view AND in the emulator, but it looks very weird on my phone. Also, the buttons don't show any reaction animation when pressed.... Kinda like a static image.
My minimum SDK for the project is 5.0 lollipop and my phone is 5.1 lollipop.
The first attached image is the design view, and that's exactly how it looks in the emulator. The second image is a screenshot from my phone.
 

Attachments

  • IMG_20170614_085828_304.JPG
    IMG_20170614_085828_304.JPG
    56.6 KB · Views: 102
  • Screenshot_2017-06-14-08-58-56.png
    Screenshot_2017-06-14-08-58-56.png
    42.7 KB · Views: 173
Please post your xml layout.

Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:eek:rientation="vertical"
    android:weightSum="1"
    tools:context="com.youngdon.mycalculator.MainActivity">

    <TextView
        android:id="@+id/operaView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="10dp"
        android:text="0"
        android:textAlignment="textEnd"
        android:textSize="40dp" />

    <TextView
        android:id="@+id/resultView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingBottom="0dp"
        android:paddingEnd="0dp"
        android:paddingLeft="0dp"
        android:paddingRight="0dp"
        android:paddingStart="0dp"
        android:paddingTop="0dp"
        android:text="200"
        android:textAlignment="textEnd"
        android:textSize="60dp" />

    <GridLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:eek:rientation="horizontal">

        <Button
            android:id="@+id/button7"
            android:layout_alignStart="@id/operaView"
            android:layout_columnWeight="1"
            android:layout_rowWeight="1"
            android:background="@android:color/holo_red_light"
            android:eek:nClick="PressedNumber"
            android:text="7"
            android:textColor="@android:color/white"
            android:textSize="40sp" />

        <Button
            android:id="@+id/button8"
            android:layout_columnWeight="1"
            android:layout_rowWeight="1"
            android:background="@android:color/holo_red_light"
            android:eek:nClick="PressedNumber"
            android:text="8"
            android:textColor="@android:color/white"
            android:textSize="40sp" />

        <Button
            android:id="@+id/button9"
            android:layout_columnWeight="1"
            android:layout_rowWeight="1"
            android:background="@android:color/holo_red_light"
            android:eek:nClick="PressedNumber"
            android:text="9"
            android:textColor="@android:color/white"
            android:textSize="40sp" />

        <Button
            android:id="@+id/button4"
            android:layout_column="0"
            android:layout_columnWeight="1"
            android:layout_row="1"
            android:layout_rowWeight="1"
            android:background="@android:color/holo_red_light"
            android:eek:nClick="PressedNumber"
            android:text="4"
            android:textColor="@android:color/white"
            android:textSize="40sp" />

        <Button
            android:id="@+id/button5"
            android:layout_column="1"
            android:layout_columnWeight="1"
            android:layout_row="1"
            android:layout_rowWeight="1"
            android:background="@android:color/holo_red_light"
            android:eek:nClick="PressedNumber"
            android:text="5"
            android:textColor="@android:color/white"
            android:textSize="40sp" />

        <Button
            android:id="@+id/button."
            android:layout_column="0"
            android:layout_columnWeight="1"
            android:layout_row="3"
            android:layout_rowWeight="1"
            android:background="@android:color/holo_red_light"
            android:eek:nClick="PressedNumber"
            android:text="."
            android:textColor="@android:color/white"
            android:textSize="40sp" />

        <Button
            android:id="@+id/button3"
            android:layout_column="2"
            android:layout_columnWeight="1"
            android:layout_row="2"
            android:layout_rowWeight="1"
            android:background="@android:color/holo_red_light"
            android:eek:nClick="PressedNumber"
            android:text="3"
            android:textColor="@android:color/white"
            android:textSize="40sp" />

        <Button
            android:id="@+id/button1"
            android:layout_column="0"
            android:layout_columnWeight="1"
            android:layout_row="2"
            android:layout_rowWeight="1"
            android:background="@android:color/holo_red_light"
            android:eek:nClick="PressedNumber"
            android:text="1"
            android:textColor="@android:color/white"
            android:textSize="40sp" />

        <Button
            android:id="@+id/button0"
            android:layout_column="1"
            android:layout_columnWeight="1"
            android:layout_row="3"
            android:layout_rowWeight="1"
            android:background="@android:color/holo_red_light"
            android:eek:nClick="PressedNumber"
            android:text="0"
            android:textColor="@android:color/white"
            android:textSize="40sp" />

        <Button
            android:id="@+id/button6"
            android:layout_column="2"
            android:layout_columnWeight="1"
            android:layout_row="1"
            android:layout_rowWeight="1"
            android:background="@android:color/holo_red_light"
            android:eek:nClick="PressedNumber"
            android:text="6"
            android:textColor="@android:color/white"
            android:textSize="40sp" />

        <Button
            android:id="@+id/buttonMinus"
            android:layout_column="3"
            android:layout_columnWeight="1"
            android:layout_row="1"
            android:layout_rowWeight="1"
            android:background="@android:color/holo_red_light"
            android:eek:nClick="PressedOp"
            android:text="-"
            android:textColor="@android:color/white"
            android:textSize="40sp" />

        <Button
            android:id="@+id/buttonPlus"
            android:layout_column="3"
            android:layout_columnWeight="1"
            android:layout_row="0"
            android:layout_rowWeight="1"
            android:background="@android:color/holo_red_light"
            android:eek:nClick="PressedOp"
            android:text="+"
            android:textColor="@android:color/white"
            android:textSize="40sp" />

        <Button
            android:id="@+id/button2"
            android:layout_column="1"
            android:layout_columnWeight="1"
            android:layout_row="2"
            android:layout_rowWeight="1"
            android:background="@android:color/holo_red_light"
            android:eek:nClick="PressedNumber"
            android:text="2"
            android:textColor="@android:color/white"
            android:textSize="40sp" />

        <Button
            android:id="@+id/buttonEqual"
            android:layout_column="2"
            android:layout_columnWeight="1"
            android:layout_row="3"
            android:layout_rowWeight="1"
            android:background="@android:color/holo_red_light"
            android:text="="
            android:textColor="@android:color/white"
            android:textSize="40sp"
            android:eek:nClick="PressedResult"/>

        <Button
            android:id="@+id/buttonTimes"
            android:layout_column="3"
            android:layout_columnWeight="1"
            android:layout_row="2"
            android:layout_rowWeight="1"
            android:background="@android:color/holo_red_light"
            android:eek:nClick="PressedOp"
            android:text="x"
            android:textColor="@android:color/white"
            android:textSize="40sp" />

        <Button
            android:id="@+id/buttonDivide"
            android:layout_column="3"
            android:layout_columnWeight="1"
            android:layout_row="3"
            android:layout_rowWeight="1"
            android:background="@android:color/holo_red_light"
            android:eek:nClick="PressedOp"
            android:text="÷"
            android:textColor="@android:color/white"
            android:textSize="40sp" />

        <Button
            android:id="@+id/buttonC"
            android:layout_column="0"
            android:layout_columnWeight="1"
            android:layout_row="5"
            android:layout_rowWeight="1"
            android:background="@android:color/holo_red_light"
            android:eek:nClick="PressedFunction"
            android:text="C"
            android:textColor="@android:color/white"
            android:textSize="40sp" />

        <Button
            android:id="@+id/buttonSr"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_column="2"
            android:layout_columnWeight="1"
            android:layout_row="5"
            android:layout_rowWeight="1"
            android:background="@android:color/holo_red_light"
            android:text="√"
            android:textColor="@android:color/white"
            android:textSize="40sp"
            android:eek:nClick="PressedResult" />

        <Button
            android:id="@+id/buttonDel"
            android:layout_height="wrap_content"
            android:layout_column="1"
            android:layout_columnWeight="1"
            android:layout_marginEnd="0dp"
            android:layout_marginLeft="0dp"
            android:layout_row="5"
            android:layout_rowWeight="1"
            android:background="@android:color/holo_red_light"
            android:eek:nClick="PressedFunction"
            android:text="DEL"
            android:textColor="@android:color/white"
            android:textSize="20sp" />

        <Button
            android:id="@+id/buttonPi"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_column="3"
            android:layout_columnWeight="1"
            android:layout_row="5"
            android:layout_rowWeight="1"
            android:background="@android:color/holo_red_light"
            android:text="π"
            android:textColor="@android:color/white"
            android:textSize="40sp" />

    </GridLayout>


</LinearLayout>
 
Last edited by a moderator:
Back
Top Bottom