直接上代码和图片。
情况一:
<?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:
<?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的情况下会占据全部,和控件不太一样。
对于一般的控件来讲,可以参考http://blog.youkuaiyun.com/jincf2011/article/details/6598256。
本文深入探讨了Android布局中使用Fragment时,如何通过调整布局权重实现组件的灵活布局与显示效果。详细解释了Fragment在不同布局宽度下的表现及与普通控件的区别,提供了实际代码示例,并对比了布局属性对Fragment行为的影响。
3468

被折叠的 条评论
为什么被折叠?



