kg96
kg96

Reputation: 73

How to make a numpad similar layout in android

How do i make the numpad layout as shown in the uploaded picture. Numpad

This is my current code which would not show anything in the design view. I used this code previously on other views which work but this time it does not work and none of the buttons were visible at all in the design view.And also how do i make the 0 button as it is in the picture. This is my 2nd time asking questions in stackoverflow so do let me know if my questions are not clear and also english is not my first language. Thank you in advanced!

Edit: I have to make this layout through xml coding and not the usual thing where the users click on the textview and the numpad of the phone shows up. I hope this clarify the doubts of my question. I have to make the clear, cancel and exit button as well.

<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:orientation="vertical"
          android:weightSum="4"
          android:layout_weight="4"
android:background="@drawable/background"
tools:context=".insert_amount">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="250dp">
    <VideoView
        android:id="@+id/videoview1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        />
</LinearLayout>

    <TextView
        android:id="@+id/textview1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Player"
        android:textSize="30dp"
        android:layout_marginTop="10dp"
        android:layout_gravity="center_horizontal"
        android:textColor="@color/white"
        />

<TextView
    android:id="@+id/textview2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Display ID"
    android:textSize="30dp"
    android:textStyle="bold"
    android:layout_marginTop="20dp"
    android:layout_gravity="center_horizontal"
    />

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/content_box"
    android:layout_marginTop="10dp"
    android:layout_marginStart="50dp"
    android:layout_marginEnd="50dp"
    android:orientation="vertical">

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:src="@drawable/in"
        android:layout_gravity="center_horizontal"
        android:layout_marginTop="50dp"
        />
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Top Up Amount (IN)"
        android:textSize="30dp"
        android:layout_marginTop="10dp"
        android:gravity="center_horizontal"
        />

    <TextView
        android:id="@+id/textviewnumber"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:hint="0.00"
        android:textSize="40dp"
        android:textStyle="bold"
        android:gravity="center"
        />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:weightSum="4"
        android:orientation="horizontal">

    <Button
            android:id="@+id/button1"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:background="@drawable/login_signoutbutton"
            android:layout_height="fill_parent"
            android:text="1"
            />

        <Button
            android:id="@+id/button2"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="fill_parent"
            android:background="@drawable/login_signoutbutton"
            android:text="2"
            />'

        <Button
            android:id="@+id/button3"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:background="@drawable/login_signoutbutton"
            android:layout_height="fill_parent"
            android:text="3"
            />

        <ImageButton
            android:id="@+id/buttonclear"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="fill_parent"
            android:paddingLeft="20dp"
            android:paddingRight="20dp"
            android:scaleType="fitCenter"
            android:background="@drawable/login_signoutbutton"
            android:src="@drawable/clear_button"
            android:layout_margin="20dp"
            />

Upvotes: 1

Views: 1521

Answers (2)

AskNilesh
AskNilesh

Reputation: 69681

Try this

<?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"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light">


        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:orientation="vertical">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:text="Player"
                android:textColor="#FFFFFF" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:text="12345679"
                android:textColor="#FFFFFF" />

        </LinearLayout>

    </android.support.v7.widget.Toolbar>

    <ImageView
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_gravity="center"
        android:layout_marginTop="10dp"
        android:src="@drawable/kid_goku" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="10dp"
        android:text="Top up Amount" />

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:hint="Top up Amount" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="20dp"
        android:orientation="vertical">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:orientation="horizontal">

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:orientation="vertical">

                <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_margin="2dp"
                    android:layout_marginHorizontal="2dp"
                    android:layout_weight="1"
                    android:text="1" />

                <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_margin="2dp"
                    android:layout_marginHorizontal="2dp"
                    android:layout_weight="1"
                    android:text="4" />

                <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginHorizontal="2dp"
                    android:layout_weight="1"
                    android:text="7" />


            </LinearLayout>

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:orientation="vertical">

                <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_margin="2dp"
                    android:layout_marginHorizontal="2dp"
                    android:layout_weight="1"
                    android:text="2" />

                <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_margin="2dp"
                    android:layout_marginHorizontal="2dp"
                    android:layout_weight="1"
                    android:text="5" />

                <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_margin="2dp"
                    android:layout_marginHorizontal="2dp"
                    android:layout_weight="1"
                    android:text="8" />

                <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginHorizontal="2dp"
                    android:layout_weight="1"
                    android:text="0" />


            </LinearLayout>

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:orientation="vertical">

                <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_margin="2dp"
                    android:layout_marginHorizontal="2dp"
                    android:layout_weight="1"
                    android:text="3" />

                <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_margin="2dp"
                    android:layout_marginHorizontal="2dp"
                    android:layout_weight="1"
                    android:text="6" />

                <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_margin="2dp"
                    android:layout_marginHorizontal="2dp"
                    android:layout_weight="1"
                    android:text="9" />


            </LinearLayout>

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1.5"
                android:orientation="vertical">

                <Button
                    android:layout_width="wrap_content"
                    android:layout_height="40dp"
                    android:layout_marginHorizontal="2dp"
                    android:layout_marginTop="8dp"
                    android:layout_weight="1"
                    android:background="#9b5006"
                    android:drawableLeft="@drawable/ic_camera"
                    android:text="Clear"
                    android:textColor="#FFFFFF"
                    />

                <Button
                    android:layout_width="wrap_content"
                    android:layout_height="35dp"
                    android:layout_marginHorizontal="2dp"
                    android:layout_marginTop="15dp"
                    android:layout_weight="1"
                    android:background="#9b5006"
                    android:drawableLeft="@drawable/ic_camera"
                    android:text="Cancel"
                    android:textColor="#FFFFFF"
                     />

                <Button
                    android:layout_width="wrap_content"
                    android:layout_height="35dp"
                    android:layout_marginHorizontal="2dp"
                    android:layout_marginTop="12dp"
                    android:layout_weight="1"
                    android:background="#9b5006"
                    android:drawableLeft="@drawable/ic_camera"
                    android:text="Next"
                    android:textColor="#FFFFFF" />


            </LinearLayout>

        </LinearLayout>


    </LinearLayout>


</LinearLayout>

OUTPUT

enter image description here

Upvotes: 2

Md Jubayer
Md Jubayer

Reputation: 272

Your layout height exceeding the device display. You have to use ScrollView here. Also for making the number keypad using GridLayout link will be better choice and you can easily get '0' button position using this view.

Upvotes: 0

Related Questions