2015-05-08 55 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具有像高度,宽度,边距等参数。所以,你调整你放置碎片的容器。

相关问题