2017-06-13 4 views
1

soll ich versuche, ein Layout zu implementieren, die den Bildschirm 40/60 vertikal trennt, layout_weight verwenden. HierAndroid (Xamarin) Linearlayout Layout: Gewicht nicht funktioniert als

ist der XML-Code:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:weightSum="1" 
    android:focusable="true" 
    android:focusableInTouchMode="true" 
    android:background="@drawable/background"> 
    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="0dp" 
     android:layout_weight="0.4"> 
     <Button 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:background="@color/white" /> 
    </LinearLayout> 
    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="0dp" 
     android:layout_weight="0.6"> 
     <Button 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:background="@color/black" /> 
    </LinearLayout> 
</LinearLayout> 

Dieser Code funktioniert nicht, einen leeren Bildschirm zurück. Wenn jedoch I ändern

android: layout_width = "fill_parent"

android: layout_height = "0DP"

android: layout_weight = "0.4"

(Vertical split)

zu

android: layout_width = "0DP"

android: layout_height = "fill_parent"

android: layout_weight = "0.4"

(Horizontal split)

der Code funktioniert wie beabsichtigt und das Layout teilt sich 40/60 horizontal auf. Warum funktioniert es nicht vertikal und wie kann ich das beheben? Jede Hilfe wäre willkommen!

+1

geben Eltern Layout Ausrichtung auf vertikale – Anmol

+0

@Anmol Seltsam, haben könnte schwören, ich versucht und es hat nicht funktioniert ... Danke obwohl ! Entspricht es Ihnen auch, die Frage zu beantworten, anstatt zu antworten, damit ich diesen Beitrag als beantwortet markieren kann? – Ryalis

+0

Sicher und willkommen – Anmol

Antwort

2

geben Eltern Layout Ausrichtung auf vertikale

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:weightSum="1" 
android:focusable="true" 
android:orientation="verticle" 
android:focusableInTouchMode="true" 
android:background="@drawable/background"> 
<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="0dp" 
    android:layout_weight="0.4"> 
    <Button 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:background="@color/white" /> 
</LinearLayout> 
<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="0dp" 
    android:layout_weight="0.6"> 
    <Button 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:background="@color/black" /> 
</LinearLayout> 

Verwandte Themen