转自:http://segmentfault.com/q/1010000000095725

 

如果使得一个View占用其父View的剩余空间?

 

[Android学习笔记]LinearLayout布局,剩余空间的使用

 

答案是使用:android:layout_weight = "1"

<?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:background="#ffe0e8ec"
    android:orientation="vertical" >
    
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="20dip" />

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1.0" />

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="20dip" />

</LinearLayout>

 

android:layout_weight的解释:

Layout weight is used to determine how Android divides up any left over space after the various widgets get all of the space they want.

 

相关文章:

  • 2021-08-29
  • 2021-07-19
  • 2022-12-23
  • 2021-12-05
  • 2021-09-20
  • 2021-12-16
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-08-13
  • 2021-12-12
  • 2021-11-29
  • 2021-07-29
  • 2021-07-16
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案