2016-12-21 3 views
0

Im здание это приложение, просто хочу, чтобы распределить эти кнопки одинаково на экране, это код i`m с помощью:Android Layout Вес не работает

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

Но я все еще получаю это результат, даже когда я проверить это на моем телефоне:

APP RESULT

Im новое на это так, это должно быть что-то простое, что я не могу видеть. В любом случае, заблаговременно за любую помощь!

+0

Кажется, ваша точка зрения не занимая всю ширину. Использовать ширину match_parent для корневого представления – Rahul

ответ

2

Установите родительскую LinearLayout ширину в match_parent, тогда ваши кнопки должны равномерно распределить пространство полной ширины.

+0

Работало Спасибо Очень много! –

0

Try с этим:

На вашем LinearLayout установить android:weightSum="1" и установить android:layout_width="match_parent".

После этого, на каждой кнопке установить android:layout_weight="0.20"

Помните: 0,20 (каждый layout_weight) х 5 (кнопки) = 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

Это работало Спасибо очень много! –

+0

@WildmarGomes Полезно знать. «Недурно» для моего ответа, верно? :) –

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