2016-12-21 7 views
0

Im Gebäude dieser App, will nur diese Tasten gleichmäßig auf dem Bildschirm verteilen, ist dies der Code i`m mit:Android-Layout Gewicht funktioniert nicht

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:orientation="horizontal" > 


<Button 
    android:id="@+id/tera_mt_serv" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:onClick="teraServerBt" 
    android:background="@color/gblue" 
    android:textColor="#fff" 
    android:text="@string/tera_server_st_mt_ab" 
    android:textAlignment="center" 
    android:textAllCaps="true" 
    android:layout_weight="1" 
    tools:ignore="ButtonStyle" /> 

<Button 
    android:id="@+id/tera_ff_serv" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:background="@color/gblue" 
    android:textColor="#fff" 
    android:text="@string/tera_server_st_ff_ab" 
    android:textAlignment="center" 
    android:textAllCaps="true" 
    android:layout_weight="1" 
    tools:ignore="ButtonStyle" /> 

<Button 
    android:id="@+id/tera_ch_serv" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:background="@color/gblue" 
    android:textColor="#fff" 
    android:onClick="teraServerBt" 
    android:text="@string/tera_server_st_ch_ab" 
    android:textAlignment="center" 
    android:textAllCaps="true" 
    android:layout_weight="1" 
    tools:ignore="ButtonStyle" /> 

<Button 
    android:id="@+id/tera_av_serv" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:background="@color/gblue" 
    android:textColor="#fff" 
    android:text="@string/tera_server_st_av_ab" 
    android:textAlignment="center" 
    android:textAllCaps="true" 
    android:layout_weight="1" 
    tools:ignore="ButtonStyle" /> 

<Button 
    android:id="@+id/tera_tr_serv" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:background="@color/gblue" 
    android:textColor="#fff" 
    android:text="@string/tera_server_st_tr_ab" 
    android:textAlignment="center" 
    android:textAllCaps="true" 
    android:layout_weight="1" 
    tools:ignore="ButtonStyle" /> 

Aber ich habe immer noch diese Ergebnis, auch wenn ich testen sie es auf meinem Handy:

APP RESULT

Im neu auf diese so muss es etwas einfacher sein, dass ich kann leider nicht sehen. Wie auch immer, Danke im Voraus für jede Hilfe!

+0

Scheint Ihre Ansicht nicht die volle Breite einnimmt. Verwenden Sie match_parent width für root view – Rahul

Antwort

2

Legen Sie die Breite Ihres Parent LinearLayout auf match_parent fest, dann sollten sich Ihre Schaltflächen gleichmäßig auf die gesamte Breite verteilen.

+0

Es hat sehr viel funktioniert! –

0

Versuchen mit diesem:

Auf dem Linearlayout gesetzt android:weightSum="1" und setzen android:layout_width="match_parent".

Danach setzen auf jeder Taste android:layout_weight="0.20"

Denken Sie daran: 0,20 (jeweils layout_weight) x 5 (Tasten) = 1 weightSum

<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="wrap_content" 
    android:weightSum="1" 
    android:orientation="horizontal" > 


    <Button 
     android:id="@+id/tera_mt_serv" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:onClick="teraServerBt" 
     android:textColor="#fff" 
     android:textAlignment="center" 
     android:textAllCaps="true" 
     android:layout_weight="0.20" 
     tools:ignore="ButtonStyle" /> 

    <Button 
     android:id="@+id/tera_ff_serv" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:textColor="#fff" 
     android:textAlignment="center" 
     android:textAllCaps="true" 
     android:layout_weight="0.20" 
     tools:ignore="ButtonStyle" /> 

    <Button 
     android:id="@+id/tera_ch_serv" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:textColor="#fff" 
     android:onClick="teraServerBt" 
     android:textAlignment="center" 
     android:textAllCaps="true" 
     android:layout_weight="0.20" 
     tools:ignore="ButtonStyle" /> 

    <Button 
     android:id="@+id/tera_av_serv" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:textColor="#fff" 
     android:textAlignment="center" 
     android:textAllCaps="true" 
     android:layout_weight="0.20" 
     tools:ignore="ButtonStyle" /> 

    <Button 
     android:id="@+id/tera_tr_serv" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:textColor="#fff" 
     android:textAlignment="center" 
     android:textAllCaps="true" 
     android:layout_weight="0.20" 
     tools:ignore="ButtonStyle" /> 
</LinearLayout> 
+1

Es hat sehr gut funktioniert! –

+0

@WildmarGomes Ist gut zu wissen. "Daumen hoch" für meine Antwort, oder? :) –