欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

Android layout_weight使用方法及实例

程序员文章站 2023-11-04 14:49:40
直接上代码和图片。 情况一:[html]复制代码 代码如下:

直接上代码和图片。

情况一:
[html]

复制代码 代码如下:

<?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="horizontal" >

    <fragment
        android:id="@+id/titles"
        android:layout_width="0dip"
        android:layout_height="match_parent"
        android:layout_weight="1"
        class="com.a2bgeek.fragmentdemo.titlesfragment" />

    <framelayout
        android:id="@+id/details"
        android:layout_width="0dip"
        android:layout_height="match_parent"
        android:layout_weight="2" >
    </framelayout>

</linearlayout>

<?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="horizontal" >

    <fragment
        android:id="@+id/titles"
        android:layout_width="0dip"
        android:layout_height="match_parent"
        android:layout_weight="1"
        class="com.a2bgeek.fragmentdemo.titlesfragment" />

    <framelayout
        android:id="@+id/details"
        android:layout_width="0dip"
        android:layout_height="match_parent"
        android:layout_weight="2" >
    </framelayout>

</linearlayout>

<?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="horizontal" >

    <fragment
        android:id="@+id/titles"
        android:layout_width="0dip"
        android:layout_height="match_parent"
        android:layout_weight="1"
        class="com.a2bgeek.fragmentdemo.titlesfragment" />

    <framelayout
        android:id="@+id/details"
        android:layout_width="0dip"
        android:layout_height="match_parent"
        android:layout_weight="2" >
    </framelayout>

</linearlayout>

Android layout_weight使用方法及实例

情况2:

[html]

复制代码 代码如下:

<?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="horizontal" >

    <fragment
        android:id="@+id/titles"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        class="com.a2bgeek.fragmentdemo.titlesfragment" />

    <framelayout
        android:id="@+id/details"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="2" >
    </framelayout>

</linearlayout>

<?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="horizontal" >

    <fragment
        android:id="@+id/titles"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        class="com.a2bgeek.fragmentdemo.titlesfragment" />

    <framelayout
        android:id="@+id/details"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="2" >
    </framelayout>

</linearlayout>

Android layout_weight使用方法及实例

情况三:

fragment这个东西在wrap_content的情况下会占据全部,和控件不太一样。