首页 > 系统 > Android > 正文

Android layout_weight使用方法及实例

2019-10-24 20:58:15
字体:
来源:转载
供稿:网友
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>

 

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的情况下会占据全部,和控件不太一样。


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表