2017-02-19 8 views
0

Я пытаюсь установить центр тяжести, но не работает. Вот мой XML. Что я, делаю неправильно?гравитация не работает в макете

Прилагаемый образ, как теперь выглядит XML.

я, ве один макет корня, я разделил его две части, и я хочу, каждая часть имеет центр тяжести

<LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="0dip" 
      android:layout_weight="2" 
      android:background="@color/bluefontcolor" 
      android:gravity="center_vertical" 
      android:orientation="horizontal" 
      android:weightSum="2"> 

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

       <com.developer.lucky.modernbalda.Flipmeter 
        android:id="@+id/scoreboard_1" 
        android:layout_width="0dip" 
        android:layout_height="@dimen/_60sdp" 
        android:layout_gravity="center" 
        android:layout_margin="10dp" 
        android:layout_weight="1" /> 
      </LinearLayout> 

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

       <com.developer.lucky.modernbalda.Flipmeter 
        android:id="@+id/scoreboard_2" 
        android:layout_width="0dip" 
        android:layout_height="@dimen/_60sdp" 
        android:layout_gravity="center" 
        android:layout_margin="10dp" 
        android:layout_weight="1" /> 
      </LinearLayout> 


     </LinearLayout> 

enter image description here

ответ

1

Возможно Flipmeter ширина является проблемой, так как они установлены для заполнения родителя LinearLayout, поэтому они отображаются так же широко, как и родительский (включая невидимую часть).

Попробуйте установить их ширину в wrap_content или измените их layout_gravity на gravity, чтобы решить эту проблему.

+0

я пытался не работал –

0

Попробуйте

<LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dip" 
     android:layout_weight="2" 
     android:background="@color/bluefontcolor" 
     android:gravity="center_vertical" 
     android:orientation="horizontal" 
     android:weightSum="2"> 

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

      <com.developer.lucky.modernbalda.Flipmeter 
       android:id="@+id/scoreboard_1" 
       android:layout_width="wrap_content" 
       android:layout_height="@dimen/_60sdp" 
       android:layout_margin="10dp"/> 
     </LinearLayout> 

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

      <com.developer.lucky.modernbalda.Flipmeter 
       android:id="@+id/scoreboard_2" 
       android:layout_width="wrap_content" 
       android:layout_height="@dimen/_60sdp" 
       android:layout_margin="10dp"/> 
     </LinearLayout> 
</LinearLayout> 
+0

я старался не работал –

+0

до центра любого члена в макете .... элемент должен использовать wrap_content в размерах и установить гравитацию до центра в родительском –

0

Добавить ниже атрибут в обоих Flipmeter

android:gravity="center" 

, а также удалить ниже атрибута с обеих Flipmeter потому что вы установили ширину LinearLayout в 0dp.

android:layout_gravity="center"