2013-07-03 3 views
2

Я хочу обработать свойство inputType EditText в моей пользовательской клавиатуре.Как центрировать выравнивание клавиш с пользовательской клавиатуры?

Поскольку я должен показать всего несколько ключей, я хочу выровнять их в центре клавиатуры. К сожалению, элемент <Row> не имеет атрибута android:gravity.

Я пытаюсь создать что-то подобное: Screenshot

Я думал, чтобы добавить некоторые другие ключи и держать их скрытыми, так что пространство будет занято, но я не думаю, что это хорошее решение.

Знаете ли вы, что любой способ центрировать выравнивание клавиш подряд?

Спасибо!

ответ

1

Простое решение - взять кнопки в макете, а затем взять гравитацию макета .... i m предоставляет универсальный макет, который можно запускать на всех макетах.

<?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 ask.

+1

+ 1 для приятного примера –

+1

Очень хорошая идея сделать универсальную – Alpan

Смежные вопросы