2017-01-03 3 views
0

У меня есть заголовок с tablayout и viewpager, в стороне от viewpager у меня есть другой фрагмент. первый фрагмент показывает карту. проблема в том, что она не работает на большом экране. На самом деле у него есть свободное место на вершине viewpager. когда я увеличиваю вес зрителя, он покрывает это свободное пространство. я знаю, что sumweight является суммой все веса, но он не работает здесь:LinearLayout Weightsum не работает

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    tools:context="com.example.noavaran.drugstore.Activity.MainPageActivity" 
    android:background="@android:color/transparent" 
    android:layoutDirection="rtl" 
    android:orientation="vertical"> 


    <LinearLayout 
     android:weightSum="100" 
     android:orientation="vertical" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     > 
     <RelativeLayout 

      android:layout_weight="12" 
      android:id="@+id/header_section" 
      android:layout_width="match_parent" 
      android:layout_height="0dp"> 
      <RelativeLayout 
       android:id="@+id/layout_container" 
       android:orientation="horizontal" 
       android:layout_alignParentTop="true" 
       android:layout_width="match_parent" 
       android:background="@color/color_main" 
       android:layout_height="@dimen/Tab_Head_height"> 
       <ImageView 

        android:layout_gravity="center_horizontal" 
        android:layout_alignParentLeft="true" 
        android:layout_width="wrap_content" 
        android:layout_height="match_parent" 
        android:layout_marginTop="10dp" 
        android:layout_marginLeft="5dp" 
        android:layout_marginBottom="5dp" 
        android:src="@drawable/logo" 

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

       <LinearLayout 
        android:id="@+id/top_header" 
        android:layout_width="wrap_content" 
        android:layout_centerInParent="true" 
        android:layout_height="match_parent" 
        android:orientation="vertical" 
        > 
        <TextView 
         android:id="@+id/buy_finish_message" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         fontPath="@string/fontsIran" 
         android:textStyle="bold" 
         android:textSize="@dimen/text_size_between" 

         android:text="@string/buy_message" 
         android:textColor="@android:color/white" 
         android:textAlignment="center" 
         android:layout_marginTop="10dp" 
         /> 

        <TextView 
         android:id="@+id/mainpage_addAddress" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:text="@string/add_address" 
         fontPath="@string/fontsIran" 
         android:textAlignment="center" 
         android:textColor="@android:color/white" 
         android:textSize="@dimen/text_smallest_size" 
         android:layout_marginTop="-5dp" 
         android:layout_below="@+id/buy_finish_message" 
         /> 

       </LinearLayout> 

      </RelativeLayout> 


     </RelativeLayout> 
     <com.example.noavaran.drugstore.Helper.CustomViewPager 
      android:layout_weight="77" 
      android:id="@+id/viewPager" 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_below="@+id/header_section" 
      fontPath="@string/fontsIran" 
      android:layout_above="@+id/tabs" 
      android:background="@android:color/white"/> 

     <android.support.design.widget.TabLayout 
      android:layout_weight="12" 
      android:id="@+id/tabs" 
      android:layout_gravity="right" 
      app:tabGravity="fill" 
      fontPath="@string/fontsIran" 
      app:tabTextAppearance="@drawable/selected_text" 
      android:layoutDirection="rtl" 
      app:tabIndicatorColor="@android:color/transparent" 
      app:tabBackground="@drawable/tabformat" 
      app:tabTextColor="@android:color/white" 
      app:tabSelectedTextColor="@color/color_tab_gray" 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:background="@color/color_main" 
      > 

     </android.support.design.widget.TabLayout> 

    </LinearLayout> 
    <android.support.design.widget.FloatingActionButton 
     android:layout_below="@+id/mainpage_addAddress" 
     android:maxHeight="100dp" 
     android:maxWidth="100dp" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/getaddress" 
     app:fabSize="mini" 
     android:scaleType="centerCrop" 
     android:id="@+id/fav_GetAddress" 
     android:onClick="fav_GetAddress" 
     app:backgroundTint="@color/color_main" 
     android:elevation="4dp" 
     app:borderWidth="0dp" 
     app:layout_anchorGravity="bottom|center" 
     app:layout_anchor="@+id/top_header" 
     /> 
</android.support.design.widget.CoordinatorLayout> 

enter image description here

+0

'weightSum' является полностью необязательным. Кроме этого, вы можете избежать некоторых уровней вложенности, поскольку вложенность влияет на производительность (отрицательно) –

+0

@Rotwang, но почему я получаю это пустое пространство. – AndroidDev

+0

Возможно, вы добавили слишком много полей в свои представления. Поля добавят дополнительное пространство. –

ответ

-1

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

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