2017-01-24 6 views
1

У меня есть небольшой linearlayout с другим linearlayout, который имеет некоторые ошибки, когда я добавляю к нему весы и стараюсь, чтобы он занял весь экран. Пожалуйста, проверьте мой код и помогите мне.Элементы линейной компоновки, не занимающие весь экран

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 

    android:orientation="horizontal" 

    android:id="@+id/linear_layout_two" 
    android:layout_below="@+id/linear_layout_one" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true"> 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="60dp" 
     android:orientation="vertical"> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:textSize="25dp" 
      android:textColor="#3193b9" 
      android:text="99.3%" 
      android:layout_weight="1" 
      android:id="@+id/goals_accuracy"/> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:textSize="10dp" 
      android:gravity="center" 
      android:text="Goals accuracy" 
      android:layout_weight="1" 
      android:id="@+id/goals_accuracy_2"/> 

    </LinearLayout> 


    <ImageView 
     android:layout_width="0dp" 
     android:layout_height="60dp" 
     android:src="@drawable/the_vertical" 

     android:id="@+id/imageView8" /> 


    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="60dp" 
     android:orientation="vertical"> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:textSize="25dp" 
      android:textColor="#3193b9" 
      android:text="10:30hr" 
      android:gravity="center" 
      android:layout_weight="1" 
      android:id="@+id/total_time_on_ice"/> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:textSize="10dp" 
      android:text="Total time on ice" 
      android:gravity="center" 
      android:layout_weight="1" 
      android:id="@+id/total_time_on_ice_2"/> 

    </LinearLayout> 
</LinearLayout> 

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

+0

Ваша проблема в том, что ваш 2 sub linearlayout не принимает всю родительскую ширину? – firegloves

+0

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

ответ

0

Попробуйте

<LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:id="@+id/linear_layout_two" 
     android:layout_below="@+id/linear_layout_one" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true"> 

    <LinearLayout 
      android:layout_width="0dp" 
      android:layout_weight="1" 
      android:layout_height="60dp" 
      android:orientation="vertical" 
      > 

     <TextView 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:textSize="25dp" 
       android:textColor="#3193b9" 
       android:text="99.3%" 
       android:layout_weight="1" 
       android:id="@+id/goals_accuracy"/> 

     <TextView 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:textSize="10dp" 
       android:gravity="center" 
       android:text="Goals accuracy" 
       android:layout_weight="1" 
       android:id="@+id/goals_accuracy_2"/> 

    </LinearLayout> 

    <LinearLayout 
      android:layout_width="0dp" 
      android:layout_weight="1" 
      android:layout_height="60dp" 
      android:orientation="vertical"> 

     <TextView 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:textSize="25dp" 
       android:textColor="#3193b9" 
       android:text="10:30hr" 
       android:gravity="center" 
       android:layout_weight="1" 
       android:id="@+id/total_time_on_ice"/> 

     <TextView 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:textSize="10dp" 
       android:text="Total time on ice" 
       android:gravity="center" 
       android:layout_weight="1" 
       android:id="@+id/total_time_on_ice_2"/> 

    </LinearLayout> 
</LinearLayout> 

Я упал ImageView, добавить фон, рендерить правую границу к вашему Fisrt LinearLayout

Краткое объяснение:

Я присвоенного каждому LinearLayout равноправным вес 1. Таким образом, они имеют половину родительской ширины каждый. И добавлена ​​width = 0dp, потому что у вас есть горизонтальный родительский LinearLayout, поэтому вы должны установить ширину 0 сыновей.

ImageView вместо этого не полезен, вы можете достичь цели границы, как я объяснил. Таким образом, вы также можете упростить свой xml

+0

it работает !! не могли бы вы объяснить, что вы сделали ...? –

+0

Я отредактировал свой ответ – firegloves

0

Некоторые примечания:

  • Почему ваши ImageView элементы 0 ширина?
  • В TextView элементы, имеющие android:layout_weight="1" должны иметь высоту 0

Это должно решить вашу проблему.

+0

Я прочитал ответ на stackoverflow и попытался, но он не работал:/ –