0

Я не пытаюсь сосредоточить взгляд на View, так как моя проблема в том, что у меня есть разделительная линия, которая должна опускаться посередине. Чтобы сделать разделительную линию, я сделал LinearLayout и дал ей цвет фона. Однако есть и другие LinearLayouts с обеих сторон.Как центрировать вертикальную LinearLayout горизонтально?

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

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:paddingRight="10dp" 
     android:layout_gravity="center"> 

     <TextView 
      android:id="@+id/changed_text" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:textSize="20sp" 
      android:text="@string/confidential" 
      android:gravity="left"/> 

     <TextView 
      android:id="@+id/please_help_me" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:textSize="60sp" 
      android:text="@string/changed_this_too" 
      android:gravity="center_horizontal"/> 
    </LinearLayout> 

    <LinearLayout 
    android:layout_width="1.5dp" 
    android:layout_height="match_parent" 
    android:background="#0097ff" 
    android:orientation="vertical" 
    android:layout_marginTop="10dp" 
    android:layout_gravity="center" 
    android:gravity="center"/> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:paddingLeft="10dp" 
     android:layout_gravity="center"> 

     <TextView 
      android:id="@+id/have_tried_everything" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:textSize="20sp" 
      android:text="@string/indeed" 
      android:gravity="left"/> 

     <TextView 
      android:id="@+id/you_are_my_last_chance" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:textSize="60sp" 
      android:text="@string/yes" 
      android:gravity="center_horizontal"/> 
    </LinearLayout> 

</LinearLayout> 

Вы можете, вероятно, сказать, что LinearLayout в середине является тот, который делает линию. Я изменил много параметров android: layout_width, а также большое количество android: gravity and android: layout_gravity, чтобы попытаться заставить его работать. Но я ничего не получил. По какой-то причине моя разделительная линия всегда слева и никогда не центрирована. Это может иметь какое-то отношение к некоторым значениям android: layout_width = "wrap_content".

Я просмотрел несколько руководств, таких как: http://thinkandroid.wordpress.com/2010/01/14/how-to-position-views-properly-in-layouts/

но не получили ничего до сих пор.

Справка была бы серьезно оценена.

+0

Не могли бы вы включить скриншот того, как выглядит ваш макет? – NasaGeek

ответ

0

Попробуйте изменить ширину макета на 0dp и добавить вес макета 1,0 к первой и третьей дочерним линейным макетам.

+0

Пробовал, не работал. 1. Он сказал, что вложенные веса были плохими для производительности, и 2. он дал мне кучу ошибок. Хорошая идея, хотя – user3183598

+0

Какие ошибки вы получили? – NasaGeek

+0

никогда, я был просто идиотом. Я использовал android: вес вместо android: layout_weight ... он работает сейчас! Спасибо! – user3183598

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