Android(Xamarin)线性布局布局:重量未按预期工作

Android(Xamarin)线性布局布局:重量未按预期工作,android,xamarin,layout,Android,Xamarin,Layout,我正在尝试实现一个布局,使用布局权重将屏幕垂直分隔为40/60 以下是xml代码: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" andr

我正在尝试实现一个布局,使用布局权重将屏幕垂直分隔为40/60

以下是xml代码:

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

此代码不工作,返回一个空白屏幕。但是,如果我改变

android:layout\u width=“fill\u parent”

android:layout\u height=“0dp”

android:layout_weight=“0.4”

(垂直分割)

android:layout_width=“0dp”

android:layout\u height=“fill\u parent”

android:layout_weight=“0.4”

(水平分割)


代码按预期工作,布局水平拆分为40/60。为什么它不能垂直工作,我如何解决这个问题?任何帮助都将不胜感激

将父布局方向指定为垂直布局

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


给父布局方向vertical@Anmol奇怪,我发誓我试过了,但没用。。。谢谢你!另外,你介意回答问题而不是回答,这样我就可以把这篇文章标记为已回答了吗?当然可以,欢迎