2013-02-24 103 views
1

當我學習上爲什麼要將layout_width設置爲ZERO?

http://developer.android.com/reference/android/app/Fragment.html

片段只見佈局土地/ fragment_layout.xml下面的代碼:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="horizontal" 
    android:layout_width="match_parent" android:layout_height="match_parent"> 

    <fragment class="com.example.android.apis.app.FragmentLayout$TitlesFragment" 
      android:id="@+id/titles" android:layout_weight="1" 
      android:layout_width="0px" android:layout_height="match_parent" /> 

    <FrameLayout android:id="@+id/details" android:layout_weight="1" 
      android:layout_width="0px" android:layout_height="match_parent" 
      android:background="?android:attr/detailsElementBackground" /> 

</LinearLayout> 

爲什麼片段的FrameLayout的layout_width的都設置爲零? ? 我在縱向上嘗試了相同的xml,設置爲android:orientation="vertical",並顯示一個空白屏幕。那麼,那裏有什麼祕密?我的意思是縱向和橫向之間有什麼區別?那FrameLayout的特殊功能是什麼?

+2

祕密是***機器人:layout_weight = 「1」 *** [瞭解更多](http://stackoverflow.com/a/3996104/488434) – 2013-02-24 08:02:10

+0

它是一種修復了某些版本的android版本的bug,如果寬度是wrap_content或fill_parent,ght不會被正確地考慮。出於某種原因,可以在整個屏幕上正確權衡兩者。 – 2013-02-24 08:02:19

+0

@ AhmadAl-Kayyali非常感謝:)我將xml更改爲android:layout_width =「match_parent」android:layout_height =「0px」'當垂直時,它工作! – Flybywind 2013-02-24 08:13:55

回答

1

您正在尋找的東西是將您的LinearLayout分成兩個等份的重量屬性。

祕密是機器人:layout_weight =「1」learn more

0

如果你的LinearLayout是垂直方向比layout_weight屬性的每個項目都layout_height設置爲0

在你有水平的LinearLayout的情況下,到layout_width設置爲0,如果它已layout_weight

相關問題