简体   繁体   English

如何在线性布局中制作一半的框架布局和一半的网格布局?

[英]How to make in Linear layout half Frame Layout and half Grid Layout?

I am trying to accomplish in xml to show half frame layout and half grid layout without specifying it by myself with dp Here is what i want: 我试图在xml中完成以显示半帧布局和半网格布局,而不用dp自己指定它,这是我想要的:

<?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:orientation="vertical" >

    <FrameLayout
        android:id="@+id/top"
        android:layout_width="match_parent"
        android:layout_height="250dp"
        android:background="#FFFF00"
        android:layout_weight="0"
        android:orientation="vertical" >

    </FrameLayout>

    <GridView
        android:id="@+id/buttom"
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        android:numColumns="3" >
    </GridView>

</LinearLayout>

I don't want to specify size of this: 我不想指定此尺寸:

android:layout_height="250dp"

As i would then need to recreate this xml for all sizes. 因为我随后需要为所有大小重新创建此xml。 Maybe i could change something and android will calculate for all sizes ? 也许我可以更改某些内容,而android将为所有尺寸计算?

Thanks. 谢谢。

You can specify weight property as follows 您可以指定体重属性,如下所示

<?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:orientation="vertical" >

    <FrameLayout
        android:id="@+id/top"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:background="#FFFF00"
        android:layout_weight="1" >

    </FrameLayout>

    <GridView
        android:id="@+id/buttom"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:numColumns="3" 
        android:layout_weight="1">
    </GridView>

</LinearLayout>

通过在framelayout和gridview中添加layout_weight="1"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM