2013-05-25 10 views
9

Jak mogę zrobić z LinearLayout wysokość pół fill_parent w xml?Wysokość w połowie wypełnienie_parent xml

<LinearLayout android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:weightSum="1"> 
     <ImageView android:layout_height="fill_parent" 
       android:layout_width="0dp" 
       android:layout_weight="0.5"/> 
</LinearLayout> 

Chciałbym zrobić coś podobnego z wysokością.

+0

zamiast fill_parent podać w dp wartość wymaganą. Jak 100dp lub cokolwiek chcesz. – Raghunandan

+0

chcesz, aby Twój linearLayout był podniesiony do kwadratu? – Blackbelt

+0

Po prostu chcę mieć połowę ekranu z 1 liniowym rzutem i pół ekranu z innym – lexell

Odpowiedz

24

I just want have a half of screen with 1 linearLayout and half screen with other one

Spróbuj tego

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

    <LinearLayout android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:background="#192832"></LinearLayout> 

    <LinearLayout android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:background="#193222"></LinearLayout> 


</LinearLayout> 

dwa układy liniowe zajmujące połowę ekranu każdego.

+0

jest logiczny, dzięki – lexell

+0

Możesz także użyć layout_height = "0dp" dla stałej wysokości –

+2

Zauważ, że 'fill_parent' został zaalokowany. Użyj 'match_parent' dla API 8 lub wyżej. ([docs] (http://developer.android.com/reference/android/view/ViewGroup.LayoutParams.html)) – Keith

Powiązane problemy