我有什么:
activity_comics.xml
- 两个 fragment 的布局容器:漫画列表 (view_comicses.xml) 和详细漫画 View
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:id="@+id/comics_fragment_container">
</FrameLayout>
view_comicses.xml
- 带有交错 ListView 的 fragment
<com.agimind.widget.huewu.pla.lib.MultiColumnListView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:pla="http://schemas.android.com/apk/res-auto"
android:id="@+id/multicollist"
android:layout_width="match_parent"
android:layout_height="match_parent"
pla:plaColumnNumber="2"
pla:plaLandscapeColumnNumber="3">
</com.agimind.widget.huewu.pla.lib.MultiColumnListView>
view_comics_detail.xml
- 漫画详细 View 的 fragment
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/black">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/comics_image"
android:layout_centerInParent="true" />
</RelativeLayout>
将view_comics.xml
和view_comics_detail.xml
fragment 添加到activity_comics.xml
后,生成的布局应该是这样的:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:id="@+id/comics_fragment_container">
<com.agimind.widget.huewu.pla.lib.MultiColumnListView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:pla="http://schemas.android.com/apk/res-auto"
android:id="@+id/multicollist"
android:layout_width="match_parent"
android:layout_height="match_parent"
pla:plaColumnNumber="2"
pla:plaLandscapeColumnNumber="3">
</com.agimind.widget.huewu.pla.lib.MultiColumnListView>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/black">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/comics_image"
android:layout_centerInParent="true" />
</RelativeLayout>
</FrameLayout>
但由于某些原因导致的布局看起来像这样
RelativeLayout
的宽度和高度等于 match_parent,但在渲染时就好像等于 wrap_content。为什么会这样?我尝试了 FrameLayout
和 RelativeLayout
的不同参数,但没有用,我们将不胜感激!
最佳答案
RelativeLayout 试图匹配 FrameLayout 的宽度但不能,因为 MultiColumnListView 在那里。然后 FrameLayout 将它的可用空间分配给两个 child 。
如果您希望 RelativeLayout 和 MultiColumnListView 都具有与 FrameLayout 相同的宽度(并且重叠),则需要将 FrameLayout 更改为 RelativeLayout。
FrameLayout更多的是用来展示单个child。可以添加多个 child ,但您需要为每个 child 指定 android:layout_gravity 以控制他们的位置。
关于Android: RelativeLayout inside FrameLayout, width height 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20349430/