Android layout_weight使用方法及实例

 更新时间:2013年06月03日 11:13:27   作者:  
Android layout_weight使用方法及实例,需要的朋友可以参考一下

直接上代码和图片。

情况一:
[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>

情况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>

情况三:

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

相关文章

  • Android application捕获崩溃异常怎么办

    Android application捕获崩溃异常怎么办

    Android application捕获崩溃异常怎么办?这篇文章主要为大家详细介绍了Android application捕获崩溃异常的相关资料
    2017-06-06
  • 详解App保活实现原理

    详解App保活实现原理

    一直以来,App 进程保活都是各大厂商,特别是头部应用开发商永恒的追求。毕竟App 进程死了,就什么也干不了了;一旦 App 进程死亡,那就再也无法在用户的手机上开展任何业务,所有的商业模型在用户侧都没有立足之地
    2021-06-06
  • 实例讲解Android中的View类以及自定义View控件的方法

    实例讲解Android中的View类以及自定义View控件的方法

    这篇文章主要介绍了Android中的View类以及自定义View控件的方法,讲解了如何继承View类并且展示了一个对View进行重绘的例子,需要的朋友可以参考下
    2016-04-04
  • Android手机悬浮窗口小案例

    Android手机悬浮窗口小案例

    这篇文章主要为大家详细介绍了Android手机悬浮窗口小案例,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2016-11-11
  • Android沉浸式状态栏的实现代码

    Android沉浸式状态栏的实现代码

    这篇文章主要为大家详细介绍了Android沉浸式状态栏的实现代码,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2017-09-09
  • Android Material组件库日期选择和时间选择器的使用方法

    Android Material组件库日期选择和时间选择器的使用方法

    这篇文章主要介绍了Android Material组件库(日期选择和时间选择器)基本使用,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧
    2023-11-11
  • Android MVP BaseFragment 通用式封装的实现

    Android MVP BaseFragment 通用式封装的实现

    这篇文章主要介绍了Android MVP BaseFragment 通用式封装的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2019-08-08
  • Android列表实现(1)_数组列表实例介绍

    Android列表实现(1)_数组列表实例介绍

    最近开始学习android的ui,先上几个相关的例子,后续还会有更新,感兴趣的朋友可以研究下
    2012-12-12
  • Android自定义View实现圆弧进度效果

    Android自定义View实现圆弧进度效果

    这篇文章主要为大家详细介绍了Android自定义View实现圆弧进度效果,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2018-11-11
  • Android 图片网格布局控件示例代码

    Android 图片网格布局控件示例代码

    本篇文章主要介绍了Android 图片网格布局控件示例代码,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2017-06-06

最新评论