2017-01-03 2 views
0

Ich habe eine Kopfzeile mit Tablayout und Viewpager, in der Seite der Viewpager habe ich verschiedene Fragment. Das erste Fragment zeigt die Karte. das Problem, das ich habe, ist, dass es Layout auf großen Bildschirm nicht funktioniert. In der Tat hat es oben auf Viewpager etwas freien Platz. Wenn ich das Gewicht des Viewpagers erhöhe, wird der freie Platz abgedeckt. ich weiß, dass der sumweight die Summe alle Gewichts ist, aber es funktioniert hier nicht:Das LinearLayout Weightsum funktioniert nicht

<?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' ist völlig optional. Ansonsten könntest du einige Verschachtelungsebenen vermeiden, da sich die Verschachtelung auf die Leistung auswirkt (negativ) –

+0

@Rotwang aber warum bekomme ich diesen leeren Platz – AndroidDev

+0

Du hast möglicherweise zu viele Ränder zu deinen Ansichten hinzugefügt. Ränder werden zusätzlichen Platz hinzufügen. –

Antwort

-1

layout_weight ist eine Eigenschaft von Linearlayout, so dass Sie es nicht in RelativeLayout verwenden können. Wickeln Sie stattdessen Ihre verschachtelten Ansichten mit einem LinearLayout und wenden Sie dann eine Gewichtung auf sie an.

Verwandte Themen