2013-05-25 15 views
9

Come posso fare con LinearLayout altezza mezza fill_parent in xml?Altezza half fill_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> 

Mi piacerebbe fare qualcosa di simile con l'altezza.

+0

invece di fill_parent specificare in dp il valore richiesto. Come 100dp o qualsiasi cosa tu voglia. – Raghunandan

+0

vuoi che il tuo linearLayout sia quadrato? – Blackbelt

+0

Voglio solo metà dello schermo con 1 linearLayout e metà schermo con l'altro – lexell

risposta

24

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

provare questo

<?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> 

due layout lineari che occupano la metà dello schermo ciascuno.

+0

è logico, grazie – lexell

+0

Puoi anche usare layout_height = "0dp" per altezza fissa –

+2

Nota che 'fill_parent' è stato deprecato. Utilizza 'match_parent' per API 8 o versioni successive. ([Docs] (http://developer.android.com/reference/android/view/ViewGroup.LayoutParams.html)) – Keith

Problemi correlati