android - 设计自定义键盘

时间:2015-06-18 10:50:23

标签: android keyboard

我想知道设计键盘的最佳方式是什么

  

第一个问题

我面对定位(Del,Clear)按钮

我用weightsum 2设计linearlayour(垂直), 每个按钮1,但他们没有完整的视图

  

第二个问题

Del函数,我需要删除光标前的字符,当Edittext为空时移动到上一个EditText

谢谢

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/voucherrelative"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:id="@+id/vouchertxt"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:layout_marginTop="20dp"
        android:gravity="center"
        android:text="Enter Voucher Code"
        android:textSize="25sp" />

    <LinearLayout
        android:id="@+id/linearLayout22"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_marginTop="5dp"
        android:layout_below="@+id/codeLinear"
        android:orientation="horizontal"
        android:weightSum="4"
        >

        <Button
            android:id="@+id/scanqr"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginRight="5dp"
            android:layout_marginLeft="5dp"
            android:layout_weight="2"
            android:layout_marginBottom="5dp"
            android:background="@drawable/roundedwhite"
            android:text="Scan "
            android:textColor="#191919" />

        <Button
            android:id="@+id/buttoncheck"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="2"
            android:background="@drawable/roundedbutton"
            android:text="Check"
            android:layout_marginRight="5dp"
            android:layout_marginLeft="5dp"
            android:textColor="#ffffff"

            />

    </LinearLayout>

    <LinearLayout
        android:id="@+id/codeLinear"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_below="@+id/vouchertxt"
        android:layout_marginBottom="20dp"
        android:layout_marginTop="20dp"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:orientation="horizontal"
        android:weightSum="3">

        <EditText
            android:singleLine="true"
            android:inputType="number"
            android:imeOptions="actionDone"
            android:id="@+id/code1"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginRight="2dp"
            android:layout_weight="1"
            android:focusable="true"
            android:focusableInTouchMode="true"
            android:gravity="center"
            android:maxLength="3"
            android:textSize="25dp" />


        <EditText
            android:imeOptions="actionNext"
            android:id="@+id/code2"
            android:inputType="number"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginRight="2dp"
            android:layout_weight="1"
            android:gravity="center"
            android:maxLength="3"
            android:textSize="25dp" />

        <EditText
            android:id="@+id/code3"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:inputType="number"
            android:maxLength="3"
            android:textSize="25dp" />

    </LinearLayout>




      <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@+id/linearLayout22"
            android:layout_marginTop="5dp">

            <LinearLayout
                android:id="@+id/linearLayout2"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_marginBottom="5dp"
                android:orientation="horizontal"
                android:weightSum="3">

                <Button
                    android:id="@+id/button7"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_marginRight="2dp"
                    android:layout_weight="1"
                    android:background="@drawable/roundedbutton"
                    android:text="7"

                    android:textColor="#ffffff"

                    />

                <Button
                    android:id="@+id/button8"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/codeLinear"
                    android:layout_marginRight="2dp"
                    android:layout_toEndOf="@+id/linearLayout2"
                    android:layout_toRightOf="@+id/linearLayout2"
                    android:layout_weight="1"
                    android:background="@drawable/roundedbutton"
                    android:text="8"
                    android:textColor="#ffffff" />

                <Button
                    android:id="@+id/button9"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_alignEnd="@+id/button9"
                    android:layout_alignRight="@+id/button9"
                    android:layout_below="@+id/codeLinear"
                    android:layout_marginRight="2dp"
                    android:layout_weight="1"
                    android:background="@drawable/roundedbutton"
                    android:text="9"
                    android:textColor="#ffffff"

                    />


            </LinearLayout>

            <LinearLayout
                android:id="@+id/linearLayout3"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                android:layout_below="@+id/linearLayout2"
                android:layout_marginBottom="5dp"
                android:orientation="horizontal"
                android:weightSum="3">

                <Button
                    android:id="@+id/button4"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_marginRight="2dp"
                    android:layout_weight="1"
                    android:background="@drawable/roundedbutton"
                    android:text="4"
                    android:textColor="#ffffff" />

                <Button
                    android:id="@+id/button5"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/codeLinear"
                    android:layout_marginRight="2dp"
                    android:layout_toEndOf="@+id/linearLayout2"
                    android:layout_toRightOf="@+id/linearLayout2"
                    android:layout_weight="1"
                    android:background="@drawable/roundedbutton"
                    android:text="5"
                    android:textColor="#ffffff" />

                <Button
                    android:id="@+id/button6"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_alignEnd="@+id/button9"
                    android:layout_alignRight="@+id/button9"
                    android:layout_below="@+id/codeLinear"
                    android:layout_weight="1"
                    android:background="@drawable/roundedbutton"
                    android:text="6"
                    android:textColor="#ffffff"

                    />

            </LinearLayout>

            <LinearLayout
                android:id="@+id/linearLayout4"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                android:layout_below="@+id/linearLayout3"
                android:layout_marginBottom="5dp"
                android:orientation="horizontal"
                android:weightSum="3">

                <Button
                    android:id="@+id/button1"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_marginRight="2dp"
                    android:layout_weight="1"
                    android:background="@drawable/roundedbutton"
                    android:text="1"
                    android:textColor="#ffffff" />

                <Button
                    android:id="@+id/button2"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/codeLinear"
                    android:layout_marginRight="2dp"
                    android:layout_toEndOf="@+id/linearLayout2"
                    android:layout_toRightOf="@+id/linearLayout2"
                    android:layout_weight="1"
                    android:background="@drawable/roundedbutton"
                    android:text="2"
                    android:textColor="#ffffff" />

                <Button
                    android:id="@+id/button3"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/codeLinear"
                    android:layout_marginRight="2dp"
                    android:layout_weight="1"
                    android:background="@drawable/roundedbutton"
                    android:text="3"
                    android:textColor="#ffffff"


                    />

            </LinearLayout>

            <LinearLayout
                android:id="@+id/linearLayout5"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                android:layout_below="@+id/linearLayout4"
                android:orientation="horizontal"
                android:weightSum="3"
                android:layout_alignRight="@+id/linearLayout3"
                android:layout_alignEnd="@+id/linearLayout3">

                <Button
                    android:id="@+id/button0"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_marginRight="2dp"
                    android:layout_weight="2"
                    android:background="@drawable/roundedbutton"
                    android:text="0"
                    android:textColor="#ffffff" />

                <Button
                    android:id="@+id/btn55"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_marginRight="2dp"
                    android:layout_weight="1"
                    android:background="@drawable/roundedbutton"
                    android:text="."
                    android:textColor="#ffffff"
                    />

            </LinearLayout>

            <LinearLayout
                android:orientation="vertical"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_alignParentBottom="true"
                android:layout_alignParentRight="true"
                android:layout_alignParentTop="true"
                android:layout_toRightOf="@+id/linearLayout2"
                android:layout_toEndOf="@+id/linearLayout2"
                android:weightSum="4"
                >

                <Button
                    android:id="@+id/buttonclear"
                    android:layout_above="@+id/buttonDel"
                    android:layout_width="match_parent"
                    android:layout_height="0dp"
                    android:layout_weight="6.73"
                    android:background="@drawable/roundedwhite"
                    android:text="Clear"
                    android:textColor="#191919"

                    />

                <Button
                    android:id="@+id/buttonDel"
                    android:layout_width="match_parent"
                    android:layout_height="0dp"
                    android:background="@drawable/roundedwhite"
                    android:text="Del"
                    android:layout_weight="2"

                    android:textColor="#191919"
                     />
            </LinearLayout>
        </RelativeLayout>


    </RelativeLayout>

</ScrollView>

从我的设备拍摄的屏幕

enter image description here

enter image description here

1 个答案:

答案 0 :(得分:0)

如果您的布局出现问题,那么很多。 它巨大!你应该使用 使它更面向对象,更容易阅读/更改。 您的布局可能只是LinearLayout,不需要RelativeLayout。 几乎是数字 - 它应该是一个水平方向的线性布局,有2个孩子 - 数字布局&amp; del / clear按钮。布局将是明确的4与del /清除重量3和按钮1。 数字是一个线性布局,垂直方向,4布局实际上是相同的。重量将布局分成三个,同样。 del / clear布局将平均分为两个。 这应该可以解决问题,并且会更简单。

如果你不知道如何使用标签,那么你应该阅读this