2016-08-02 20 views
-1

Ich möchte folgendes Layout erreichen.Gleiche Breite aller Knöpfe

enter image description here

Wie kann ich die Taste 0 gleich Rest der Tasten. Bitte beachten Sie, dass ich layout_weight = "1" verwendet habe, so dass alle anderen Tasten gleich lang sind, während sie dem Elternteil entsprechen. Seit dem habe ich Button 0 auf einem anderen Layout erstellt, so dass ich es nicht mit anderen Buttons gleich lang machen kann.

Hier ist mein Code so weit

<LinearLayout 

    android:orientation="horizontal" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 
    <Button 
     android:id="@+id/seven" 
     android:layout_gravity="center_horizontal" 
     android:layout_width="match_parent" 
     android:layout_weight="1" 
     android:layout_height="wrap_content" /> 
    <Button 
     android:id="@+id/eight" 
     android:layout_gravity="center_horizontal" 
     android:layout_width="match_parent" 
     android:layout_weight="1" 
     android:layout_height="wrap_content" /> 
    <Button 
     android:id="@+id/nine" 
     android:layout_gravity="center_horizontal" 
     android:layout_width="match_parent" 
     android:layout_weight="1" 
     android:layout_height="wrap_content" /> 

</LinearLayout> 
<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 
<Button 
    android:id="@+id/zero" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" /> 
</LinearLayout> 
+0

erstellen zwei "Dummy" Buttons, die unsichtbar sind, an den Seiten von Button "0". Aber lassen Sie mich vorschlagen, dass Sie eine GridView statt einer Reihe von LinearLayouts verwenden. –

Antwort

0

Nehmen Sie die Null-Taste aus dem Linearlayout, nehme ich es ein anderes Layout ist alles in definiert sind, wie ein relativ Layout? und versuche etwas in diesem Sinne.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" 
    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"> 

<LinearLayout 

    android:orientation="horizontal" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/linearLayout"> 
    <Button 
     android:id="@+id/seven" 
     android:layout_gravity="center_horizontal" 
     android:layout_width="match_parent" 
     android:layout_weight="1" 
     android:layout_height="wrap_content" /> 
    <Button 
     android:id="@+id/eight" 
     android:layout_gravity="center_horizontal" 
     android:layout_width="match_parent" 
     android:layout_weight="1" 
     android:layout_height="wrap_content" /> 
    <Button 
     android:id="@+id/nine" 
     android:layout_gravity="center_horizontal" 
     android:layout_width="match_parent" 
     android:layout_weight="1" 
     android:layout_height="wrap_content" /> 

</LinearLayout> 

<Button 
    android:id="@+id/zero" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/linearLayout" 
    android:layout_marginTop="98dp" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" 
    android:layout_alignParentRight="true" 
    android:layout_alignParentEnd="true" /> 

0

Nehmen Sie die letzte Taste in einem anderen Linearlayout und weitere Linearlayout in es mit dem Gewicht hinzufügen, versuchen Sie diesen Code ....

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" 
> 

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

    <Button 
     android:id="@+id/seven" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_horizontal" 
     android:layout_weight="1" /> 

    <Button 
     android:id="@+id/eight" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_horizontal" 
     android:layout_weight="1" /> 

    <Button 
     android:id="@+id/nine" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_horizontal" 
     android:layout_weight="1" /> 

</LinearLayout> 

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

    <LinearLayout 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="1"></LinearLayout> 

    <LinearLayout 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="1"> 

     <Button 
      android:id="@+id/zero" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" /> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="1"></LinearLayout> 
</LinearLayout> 

here is the output