2017-01-24 3 views
-1

Вот как он смотрит на данный момент. enter image description hereЦентр TextView с drawableTop в LinearLayout

Я читал другие предлагаемые здесь решения, но никому это не помогло. Я хочу сосредоточить эти 4 textview, поскольку он соответствует растягиваемому в центре по горизонтали и вертикали LinearLayout. На мобильном устройстве все работает нормально, но на планшете нижняя панель имеет более высокую высоту, и я хочу, чтобы элементы управления были центрированы.

Вот код:

<LinearLayout 
      android:id="@+id/bottomBar" 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_weight=".2" 
      android:orientation="horizontal"> 

      <com.dyve.counting.widget.DVTextView 
       android:id="@+id/txtAreaTools" 
       style="@style/BottomBarButton" 
       android:layout_weight="0.19" 
       android:background="@drawable/bottom_bar_back_with_arrow" 
       android:drawableTop="@drawable/area_tool" 
       android:textColor="@color/white" 
       android:gravity="center_horizontal" 
       android:textSize="@dimen/bottom_bar_text_size" 
       android:text="@string/area" /> 

      <com.dyve.counting.widget.DVTextView 
       android:id="@+id/clearAllTool" 
       style="@style/BottomBarButton" 
       android:layout_weight="0.19" 
       android:textColor="@color/white" 
       android:gravity="center_horizontal" 
       android:textSize="@dimen/bottom_bar_text_size" 
       android:background="@drawable/bottom_bar_back" 
       android:visibility="gone"/> 

      <FrameLayout 
       android:layout_width="0dp" 
       android:layout_weight="0.19" 
       android:layout_height="match_parent"> 
       <FrameLayout 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:layout_gravity="center"> 

        <com.dyve.counting.widget.DVTextView 
         android:id="@+id/txtToggleNumbers" 
         style="@style/BottomBarButton" 
         android:layout_width="match_parent" 
         android:layout_height="match_parent" 
         android:textSize="@dimen/bottom_bar_text_size" 
         android:textColor="@color/white" 
         android:gravity="center_horizontal" 
         android:drawableTop="@drawable/hide_numbers_tool" /> 

        <RelativeLayout 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content"> 
         <com.dyve.counting.widget.DVTextView 
          android:id="@+id/mCalibrateToolView" 
          style="@style/BottomBarButton" 
          android:layout_centerHorizontal="true" 
          android:layout_width="match_parent" 
          android:layout_height="match_parent" 
          android:layout_gravity="center_horizontal" 
          android:textColor="@color/white" 
          android:gravity="center_horizontal" 
          android:textSize="@dimen/bottom_bar_text_size" 
          android:background="@drawable/bottom_bar_back_with_arrow" 
          android:drawableTop="@drawable/show_calibrate_tool" 
          android:text="@string/calibrate_text" /> 

         <TextView 
          android:id="@+id/badgeRadius" 
          android:layout_width="@dimen/calibrate_size" 
          android:layout_height="@dimen/calibrate_size" 
          android:textColor="@color/primary_color" 
          android:textStyle="bold" 
          android:gravity="center" 
          android:layout_alignRight="@+id/mCalibrateToolView" 
          android:layout_marginRight="@dimen/calibrate_margin" 
          android:layout_marginTop="@dimen/calibrate_margin_top" 
          android:background="@drawable/shape_notification"/> 
        </RelativeLayout> 
       </FrameLayout> 
      </FrameLayout> 

      <com.dyve.counting.widget.DVTextView 
       android:id="@+id/btnCount" 
       android:layout_width="0dp" 
       android:layout_weight="0.24" 
       android:layout_height="match_parent" 
       android:textColor="@color/white" 
       style="@style/AreaToolButton" 
       android:textSize="18dp" 
       android:background="#33FFFFFF" 
       android:layout_marginTop="8dp" 
       android:layout_marginBottom="8dp" 
       android:text="@string/count_text" /> 

      <com.dyve.counting.widget.DVTextView 
       android:id="@+id/txtTagTools" 
       style="@style/BottomBarButton" 
       android:layout_weight="0.19" 
       android:textColor="@color/white" 
       android:textSize="@dimen/bottom_bar_text_size" 
       android:background="@drawable/bottom_bar_back_with_arrow" 
       android:drawableTop="@drawable/tags_tool" 
       android:gravity="center_horizontal" 
       android:text="@string/tags" /> 

      <com.dyve.counting.widget.DVTextView 
       android:id="@+id/menuTool" 
       style="@style/BottomBarButton" 
       android:layout_weight="0.19" 
       android:textColor="@color/white" 
       android:drawableTop="@drawable/bottom_more_count" 
       android:gravity="center_horizontal" 
       android:textSize="@dimen/bottom_bar_text_size" 
       android:text="@string/more" /> 
     </LinearLayout> 

Любая помощь приветствуется. Спасибо.

+0

На верхнем уровне 'LinearLayout',' android: gravity = "center_vertical" 'Не работает? – Nizam

+0

К сожалению нет. Нет визуальной разницы –

+0

Вы пробовали 'layout_gravity'? –

ответ

0

Попробуйте добавить:

android:layout_height="wrap_content" 

в твоем:

<com.dyve.counting.widget.DVTextView 
     android:id="@+id/txtAreaTools" 
     style="@style/BottomBarButton" 
     android:layout_weight="0.19" 
     android:background="@drawable/bottom_bar_back_with_arrow" 
     android:drawableTop="@drawable/area_tool" 
     android:textColor="@color/white" 
     android:gravity="center_horizontal" 
     android:textSize="@dimen/bottom_bar_text_size" 
     android:text="@string/area" /> 
+0

Спасибо, Саре, но он не работает. –

0

изменить ваш android:gravity="center_horizontal" к android:gravity="center"

+0

Не работает. Вот как это выглядит сейчас (http://imgur.com/a/S2frs). Идея состоит в том, что значок и текст должны быть центрированы по вертикали, и сейчас текст очень низкий. Если вес нижней панели больше, расстояние между изображением и текстом будет больше. –

+0

@ZackKaytranada Я не могу видеть изображение, которое вы связали в комментарии, поэтому я не мог понять, что произошло после изменения выше. –

+0

Только текст центрирован по вертикали, изображение находится в верхней части окна –

0

Пожалуйста, попробуйте заменить свой код с этим ::

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/bottomBar" 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight=".2" 
    android:orientation="horizontal"> 

    <FrameLayout 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="1"> 

     <com.dyve.counting.widget.DVTextView 
      android:id="@+id/txtAreaTools" 
      style="@style/BottomBarButton" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:background="@drawable/bottom_bar_back_with_arrow" 
      android:drawableTop="@drawable/area_tool" 
      android:gravity="center" 
      android:text="@string/area" 
      android:textColor="@color/white" 
      android:textSize="@dimen/bottom_bar_text_size" /> 
    </FrameLayout> 

    <FrameLayout 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="1"> 

     <com.dyve.counting.widget.DVTextView 
      android:id="@+id/clearAllTool" 
      style="@style/BottomBarButton" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:background="@drawable/bottom_bar_back" 
      android:gravity="center" 
      android:textColor="@color/white" 
      android:textSize="@dimen/bottom_bar_text_size" 
      android:visibility="gone" /> 
    </FrameLayout> 


    <FrameLayout 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="1"> 

     <FrameLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center"> 

      <com.dyve.counting.widget.DVTextView 
       android:id="@+id/txtToggleNumbers" 
       style="@style/BottomBarButton" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:drawableTop="@drawable/hide_numbers_tool" 
       android:gravity="center" 
       android:textColor="@color/white" 
       android:textSize="@dimen/bottom_bar_text_size" /> 

      <RelativeLayout 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center"> 

       <com.dyve.counting.widget.DVTextView 
        android:id="@+id/mCalibrateToolView" 
        style="@style/BottomBarButton" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_centerHorizontal="true" 
        android:layout_gravity="center" 
        android:background="@drawable/bottom_bar_back_with_arrow" 
        android:drawableTop="@drawable/show_calibrate_tool" 
        android:gravity="center" 
        android:text="@string/calibrate_text" 
        android:textColor="@color/white" 
        android:textSize="@dimen/bottom_bar_text_size" /> 

       <TextView 
        android:id="@+id/badgeRadius" 
        android:layout_width="@dimen/calibrate_size" 
        android:layout_height="@dimen/calibrate_size" 
        android:layout_alignRight="@+id/mCalibrateToolView" 
        android:layout_marginRight="@dimen/calibrate_margin" 
        android:layout_marginTop="@dimen/calibrate_margin_top" 
        android:background="@drawable/shape_notification" 
        android:gravity="center" 
        android:textColor="@color/primary_color" 
        android:textStyle="bold" /> 
      </RelativeLayout> 
     </FrameLayout> 
    </FrameLayout> 


    <FrameLayout 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="0.9"> 


     <com.dyve.counting.widget.DVTextView 
      android:id="@+id/btnCount" 
      style="@style/AreaToolButton" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:layout_marginBottom="8dp" 
      android:layout_marginTop="8dp" 
      android:background="#33FFFFFF" 
      android:gravity="center" 
      android:text="@string/count_text" 
      android:textColor="@color/white" 
      android:textSize="18dp" /> 
    </FrameLayout> 


    <FrameLayout 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="1"> 

     <com.dyve.counting.widget.DVTextView 
      android:id="@+id/txtTagTools" 
      style="@style/BottomBarButton" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:background="@drawable/bottom_bar_back_with_arrow" 
      android:drawableTop="@drawable/tags_tool" 
      android:gravity="center" 
      android:text="@string/tags" 
      android:textColor="@color/white" 
      android:textSize="@dimen/bottom_bar_text_size" /> 
    </FrameLayout> 


    <FrameLayout 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="1"> 

     <com.dyve.counting.widget.DVTextView 
      android:id="@+id/menuTool" 
      style="@style/BottomBarButton" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:drawableTop="@drawable/bottom_more_count" 
      android:gravity="center" 
      android:text="@string/more" 
      android:textColor="@color/white" 
      android:textSize="@dimen/bottom_bar_text_size" /> 
    </FrameLayout> 
</LinearLayout> 

Editted ::

завернул весь вид с framelayout с этим весом более that..so своего внутреннего вида обыкновения расширяться, что много ... Попробуйте новый Editted код ..

Пожалуйста скажите, если нужна дополнительная помощь ..

+0

Вот как это выглядит (http://imgur.com/a/S2frs). Идея состоит в том, что значок и текст должны быть центрированы по вертикали, и сейчас текст очень низкий. Если вес нижней панели больше, расстояние между изображением и текстом будет больше. –

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

  • Нет связанных вопросов^_^