LinearLayout Weightsum不起作用

时间:2017-01-03 15:40:55

标签: android android-layout android-linearlayout

我有一个带有tablayout和viewpager的标题,在viewpager的一边,我有不同的片段。第一个片段显示地图。 我的问题是它的布局在大屏幕上不起作用。事实上,它在viewpager顶部有一些空闲空间。当我增加viewpager重量时,它覆盖了那个自由空间。 我知道总重是所有重量的总和,但它在这里不起作用:

<?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

1 个答案:

答案 0 :(得分:-1)

layout_weight是LinearLayout的属性,因此您无法在RelativeLayout中使用它。 而是使用LinearLayout包装嵌套视图,然后对它们应用权重。