2014-01-16 29 views
0

在我的應用程序中,我有一個與以下layot行動。我有layout_weight prpr。當我使用嵌入在容器中的視圖的權重時,它也具有權重參數,但這不起作用。它可能使用嵌入式視圖重量在Android?嵌入的意見layout_weight

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/LinearLayout1" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:weightSum="10" > 

    <RelativeLayout 
     android:id="@+id/headerLayout" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_gravity="top" 
     android:layout_weight="1" 
     android:background="@color/header_color" 
     android:orientation="horizontal" > 

     <View 
      android:id="@+id/main_backView" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentBottom="true" 
      android:layout_alignParentLeft="true" 
      android:background="@null" /> 

     <ImageButton 
      android:id="@+id/menuBtn" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignBottom="@+id/appNameText" 
      android:layout_alignParentLeft="true" 
      android:layout_alignTop="@+id/appNameText" 
      android:layout_centerVertical="true" 
      android:layout_gravity="left" 
      android:layout_marginLeft="30px" 
      android:background="@null" 
      android:scaleType="fitCenter" 
      android:src="@drawable/menu" 
      tools:ignore="ContentDescription" /> 

     <TextView 
      android:id="@+id/mapClickText" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentRight="true" 
      android:layout_centerVertical="true" 
      android:layout_marginRight="30px" 
      android:text="@string/map_text" 
      android:textColor="@android:color/white" 
      android:textSize="21sp" /> 

     <TextView 
      android:id="@+id/appNameText" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerInParent="true" 
      android:text="@string/app_name" 
      android:textColor="@android:color/white" 
      android:textSize="21sp" /> 
    </RelativeLayout> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_gravity="center" 
     android:layout_weight="8" > 

     <ScrollView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:fillViewport="true" > 

      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:orientation="vertical" 
       android:weightSum="10" > 

       <RelativeLayout 
        android:id="@+id/imagePager" 
        android:layout_width="match_parent" 
        android:layout_height="0dp" 
        android:layout_gravity="top" 
        android:layout_weight="4" 
        android:background="@android:color/white" > 

        <mobi.esys.custom_components.AutoSwitchPager 
         android:id="@+id/pager" 
         android:layout_width="match_parent" 
         android:layout_height="match_parent" /> 

        <com.viewpagerindicator.CirclePageIndicator 
         android:id="@+id/indicator" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:layout_alignParentBottom="true" 
         android:layout_centerHorizontal="true" 
         android:layout_marginBottom="20px" 
         android:padding="2px" /> 

        <TextView 
         android:id="@+id/bannerText" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_centerHorizontal="true" 
         android:layout_centerVertical="true" 
         android:textColor="@android:color/white" 
         android:textSize="21sp" /> 
       </RelativeLayout> 

       <RelativeLayout 
        android:id="@+id/suggestIndicator" 
        android:layout_width="match_parent" 
        android:layout_height="0dp" 
        android:layout_gravity="center" 
        android:layout_weight="1" 
        android:background="@color/suggestions_indicator_color" > 

        <TextView 
         android:id="@+id/suggAmount" 
         android:layout_width="60px" 
         android:layout_height="match_parent" 
         android:layout_alignParentLeft="true" 
         android:layout_centerVertical="true" 
         android:layout_marginLeft="30px" 
         android:background="@drawable/circle" 
         android:gravity="center" 
         android:textColor="@color/suggestions_indicator_color" 
         android:textSize="21sp" /> 

        <TextView 
         android:id="@+id/suggText" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_alignParentTop="true" 
         android:layout_marginLeft="10px" 
         android:layout_marginTop="6px" 
         android:layout_toRightOf="@+id/suggAmount" 
         android:text="@string/sugg" 
         android:textColor="@android:color/white" 
         android:textSize="16sp" 
         android:textStyle="bold" /> 

        <TextView 
         android:id="@+id/suggVisitText" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_alignBottom="@+id/suggAmount" 
         android:layout_marginLeft="10px" 
         android:layout_toRightOf="@+id/suggAmount" 
         android:textColor="@android:color/white" 
         android:textSize="12sp" /> 

        <ImageButton 
         android:id="@+id/arrowBtn" 
         android:layout_width="30px" 
         android:layout_height="40px" 
         android:layout_alignParentRight="true" 
         android:layout_centerVertical="true" 
         android:layout_marginRight="30px" 
         android:background="@null" 
         android:scaleType="fitXY" 
         android:src="@drawable/arrow" /> 
       </RelativeLayout> 

       <GridLayout 
        android:id="@+id/whereTab" 
        android:layout_width="match_parent" 
        android:layout_height="0dp" 
        android:layout_weight="5" 
        android:columnCount="2" > 
       </GridLayout> 
      </LinearLayout> 
     </ScrollView> 
    </RelativeLayout> 

    <ImageView 
     android:id="@+id/logoImage" 
     android:layout_width="wrap_content" 
     android:layout_height="0dp" 
     android:layout_gravity="bottom" 
     android:layout_weight="1" 
     android:scaleType="fitXY" 
     android:src="@drawable/logo" 
     tools:ignore="ContentDescription" /> 

</LinearLayout> 

回答

3

重量機制分配任何第一佈局傳遞之後殘留在父線性佈局空間。 A wrap_content佈局沒有任何剩餘空間。對於它的價值,ScrollView不適用於match_parent高度。

+0

有沒有辦法在ScroollView中做到這一點? –

+0

要做什麼?如果你需要滾動,相對於屏幕尺寸來說,確定事物的大小是沒有意義的。只需讓組件佔用他們需要的任何空間,即'wrap_content'。如果滾動視圖不總是大於屏幕,請使用'android:fillViewPort =「true」'屬性。 – laalto