2015-05-08 53 views
2

我有Fragment我需要跨越屏幕的底部到頂部,從左邊緣到屏幕的80%。將片段的寬度設置爲屏幕寬度的百分比

我嘗試使用android:layout_weight="0.8"我得到的,甚至當我巢<fragment>在另一個<RelativeLayout><LinearLayout>

眼下,高度從上到下跨越,因爲android:layout_height="fill_parent" 的「佈局無效參數」消息但寬度仍然設置爲wrap_content,因爲我不知道如何設置爲屏幕寬度的80%。

<fragment 
     android:layout_width="wrap_content" 
     android:layout_height="fill_parent" 
     android:id="@+id/xFragment" 
     android:name="com.example.x.x.xFragment"/> 

謝謝

回答

5

把你的片段的線性佈局,像這樣:

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

    <fragment 
      android:layout_width="0dp" 
      android:layout_weight="8" 
      android:layout_height="fill_parent" 
      android:id="@+id/xFragment" 
      android:name="com.example.x.x.xFragment"/> 


    <View 
      android:id="@+id/otherElement" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="2"/> 

</LinearLayout> 

希望它可以幫助你!

+2

如果答案對你有用,你可以標註upvote ?? @ KNS –

1

碎片沒有參數,如高度,寬度,邊距。 View和ViewGroup具有像高度,寬度,邊距等參數。所以,你調整你放置碎片的容器。

相關問題