2012-06-07 125 views
0

我有XML,其中圖像填滿屏幕的60%:爲什麼layout_weight工作在不同設備上的不同

    <RelativeLayout 
         android:id="@+id/rl_images_layout" 
         android:layout_width="0dp" 
         android:layout_weight="6" 
         android:layout_height="wrap_content" 
         android:layout_marginBottom ="5dp"> 

         <com.my.proj.view.ContentUpdatableImageView 
          android:id="@+id/iv_template1_image" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:adjustViewBounds="true" 
          android:scaleType="fitStart" /> 

         <ImageView 
          android:id="@+id/ivResizeIcon" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:layout_alignRight="@id/iv_template1_image" 
          android:layout_alignTop="@id/iv_template1_image" 
          android:background="@drawable/btn_pinch" /> 

         <ImageView 
          android:id="@+id/ivRotateIcon" 
          android:layout_width="55dp" 
          android:layout_height="55dp" 
          android:layout_alignRight="@id/iv_template1_image" 
          android:layout_alignBottom="@id/iv_template1_image" 
          android:layout_marginRight="5dp" 
          android:layout_marginBottom="5dp" 
          android:background="@drawable/btn_rotate" 
          android:visibility="gone" /> 
       </RelativeLayout> 
       <View 
        android:layout_width="0dp" 
        android:layout_height="fill_parent" 
        android:layout_weight="4" /> 

在一個手機,它工作正常(LG P500),但在其他設備(HTC Desire HD的)圖像填充只有40%。有任何想法嗎?

+0

是什麼一個「視圖」的樣子?這是一個抽象類,所以我可以告訴你不應該像這樣使用它。在我的頭頂,這似乎是一個可能的事情。用一個'FrameLayout'替換它,看看視圖的其餘部分是否正確測量。 – DeeV

回答

0

試試這個

android:weightSum="100" //for parent layout 

    android:layout_weight="60" // for first child //In your case relative layout 

    android:layout_weight="40" //for second child //In your case view 
1

你錯過了一兩件事。

如果您正在使用android:layout_weight雙方的意見應該有fill_parent/match_parent參數作爲layout_heigth(如果你想傳播屏幕)

因此,在您第一個視圖改變layout_heigth到:

android:layout_height="fill_parent" 
相關問題