android - 设计自定义键盘
android - design custom keyboard
我想知道这样设计键盘的最佳方式是什么
First Problem
我在定位(Del,Clear)按钮中
我设计 linearlayour(vertical) with weightsum 2 ,
每个按钮 1,但它们没有填满整个视图
Second Problem
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>
我设备的屏幕截图
您的布局有很多问题。
它是巨大的!你应该使用 使其更面向 object,并且更易于 read/change。
您的布局实际上可能只是 LinearLayout,不需要 RelativeLayout。
关于数字 - 它应该是水平方向的线性布局,带有 2 children - 数字布局和 del/clear 按钮。布局将是权重 4,权重 3 的 del/clear 和权重 1 的按钮。
数字是一个垂直方向的线性布局,有 4 个几乎相同的布局。重量将布局平均分为三部分。
del/clear 布局将平均分为两部分。
这应该可以解决问题,并且会变得更加简单。
如果您不知道如何使用标签,那么您应该阅读 this
我想知道这样设计键盘的最佳方式是什么
First Problem
我在定位(Del,Clear)按钮中
我设计 linearlayour(vertical) with weightsum 2 , 每个按钮 1,但它们没有填满整个视图
Second Problem
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>
我设备的屏幕截图
您的布局有很多问题。 它是巨大的!你应该使用 使其更面向 object,并且更易于 read/change。 您的布局实际上可能只是 LinearLayout,不需要 RelativeLayout。 关于数字 - 它应该是水平方向的线性布局,带有 2 children - 数字布局和 del/clear 按钮。布局将是权重 4,权重 3 的 del/clear 和权重 1 的按钮。 数字是一个垂直方向的线性布局,有 4 个几乎相同的布局。重量将布局平均分为三部分。 del/clear 布局将平均分为两部分。 这应该可以解决问题,并且会变得更加简单。
如果您不知道如何使用标签,那么您应该阅读 this