2013-07-03 35 views
2

我想在我的自定义键盘中处理 中EditText的inputType属性。如何居中对齐自定义键盘上的按键?

由于我必须显示几个按键,我想将它们对准键盘中心。不幸的是,<Row>元素没有android:gravity属性。

我试图创建类似的东西: Screenshot

我想补充一些其他的键,并保持它们隐藏起来的空间将被占用,但我不认为这是一个很好的解决方案。

你知道任何方式来居中对齐连续的键吗?

谢谢!

回答

1

一个简单的解决方案是在布局中采取按钮,然后采取布局的重力.... 我提供了一个通用布局,它可以在所有布局上运行。

<?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" > 

    <RelativeLayout 
      android:layout_width="fill_parent" 
      android:layout_height="0dp" 
      android:layout_weight=".50" 
     ></RelativeLayout> 
    <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="0dp" 
      android:layout_weight=".50" 
      android:orientation="vertical" 
     > 

     <LinearLayout 
       android:layout_width="fill_parent" 
       android:layout_height="0dp" 
       android:layout_weight=".25" 
       android:gravity="center" 
      > 

      <Button 
        android:layout_height="wrap_content" 
        android:layout_width="wrap_content" 
        android:text="myTxt" 
       /> 
      <Button 
        android:layout_height="wrap_content" 
        android:layout_width="wrap_content" 
        android:text="myTxt" 
       /> 
      <Button 
        android:layout_height="wrap_content" 
        android:layout_width="wrap_content" 
        android:text="myTxt" 
       /> 
      <Button 
        android:layout_height="wrap_content" 
        android:layout_width="wrap_content" 
        android:text="myTxt" 
       /> 

     </LinearLayout> 
     <LinearLayout 
       android:layout_width="fill_parent" 
       android:layout_height="0dp" 
       android:layout_weight=".25" 
       android:gravity="center" 
      > 
      <Button 
        android:layout_height="wrap_content" 
        android:layout_width="wrap_content" 
        android:text="myTxt" 
       /> 
      <Button 
        android:layout_height="wrap_content" 
        android:layout_width="wrap_content" 
        android:text="myTxt" 
       /> 
      <Button 
        android:layout_height="wrap_content" 
        android:layout_width="wrap_content" 
        android:text="myTxt" 
       /> 
      <Button 
        android:layout_height="wrap_content" 
        android:layout_width="wrap_content" 
        android:text="myTxt" 
       /> 
     </LinearLayout> 
     <LinearLayout 
       android:layout_width="fill_parent" 
       android:layout_height="0dp" 
       android:layout_weight=".25" 
       android:gravity="center" 
      > 
      <Button 
        android:layout_height="wrap_content" 
        android:layout_width="wrap_content" 
        android:text="myTxt" 
       /> 
      <Button 
        android:layout_height="wrap_content" 
        android:layout_width="wrap_content" 
        android:text="myTxt" 
       /> 
      <Button 
        android:layout_height="wrap_content" 
        android:layout_width="wrap_content" 
        android:text="myTxt" 
       /> 
      <Button 
        android:layout_height="wrap_content" 
        android:layout_width="wrap_content" 
        android:text="myTxt" 
       /> 
     </LinearLayout> 
     <LinearLayout 
       android:layout_width="fill_parent" 
       android:layout_height="0dp" 
       android:layout_weight=".25" 
       android:gravity="center" 
      > 
      <Button 
        android:layout_height="wrap_content" 
        android:layout_width="wrap_content" 
        android:text="myTxt" 
       /> 
      <Button 
        android:layout_height="wrap_content" 
        android:layout_width="wrap_content" 
        android:text="myTxt" 
       /> 
      <Button 
        android:layout_height="wrap_content" 
        android:layout_width="wrap_content" 
        android:text="myTxt" 
       /> 
      <Button 
        android:layout_height="wrap_content" 
        android:layout_width="wrap_content" 
        android:text="myTxt" 
       /> 
     </LinearLayout> 


    </LinearLayout> 


</LinearLayout> 

@Ungureanu Liviu,仍然任何查询,然后plz问。

+1

+ 1很好的例子 –

+1

这是非常好的主意,使通用 – Alpan