高度为一半fill_parent xml

lex*_*ell 10 xml height android android-linearlayout

如何处理xml LinearLayout高度的一半fill_parent

<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>
Run Code Online (Sandbox Code Playgroud)

我想做一些与身高相似的事情.

Oam*_*Oam 30

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

试试这个

<?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="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="#192832"></LinearLayout>

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


</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

两个线性布局占据屏幕的一半.

  • 请注意,`fill_parent`已被删除.API 8或更高版本使用`match_parent`.([文档](http://developer.android.com/reference/android/view/ViewGroup.LayoutParams.html)) (4认同)