广

android开发

  • IOS开发
  • android开发
  • PHP编程
  • JavaScript
  • ASP.NET
  • ASP编程
  • JSP编程
  • Java编程
  • 易语言
  • Ruby编程
  • Perl编程
  • AJAX
  • 正则表达式
  • C语言
  • 编程开发

    Android layout_weight使用方法及实例

    2018-04-09 07:41:58 次阅读 稿源:互联网
    广告

    直接上代码和图片。

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

    一起学吧部分文章转载自互联网,供读者交流和学习,若有涉及作者版权等问题请及时与我们联系,以便更正、删除或按规定办理。感谢所有提供资讯的网站,欢迎各类媒体与一起学吧进行文章共享合作。

    广告
    广告
    广告