首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何同时从宿主活动中膨胀2段视图?

如何同时从宿主活动中膨胀2段视图?
EN

Stack Overflow用户
提问于 2017-11-18 08:53:11
回答 3查看 276关注 0票数 0

我在我的主要活动中有这些片段的代码。

代码语言:javascript
复制
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/mainView"
    android:orientation="vertical"
    android:layout_marginBottom="10dp">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:id="@+id/mainView2"/>


</LinearLayout>

和我在我的主要活动中使用这段代码来膨胀片段

代码语言:javascript
复制
FragmentManager fm = getSupportFragmentManager();
        fm.beginTransaction().add(R.id.mainView,new MainViewFragment())
                .add(R.id.mainView2,new SecondProductLayout())
                .commit();

但是我仍然得到了第一个片段视图,我做错了什么,我如何解决这个问题?

EN

回答 3

Stack Overflow用户

发布于 2017-11-18 09:00:53

将活动屏幕分成两部分,使活动中的片段膨胀。

票数 0
EN

Stack Overflow用户

发布于 2017-11-18 09:19:28

可以在xml中添加静态片段。请参阅这些链接:

票数 0
EN

Stack Overflow用户

发布于 2017-11-18 09:25:50

你必须用重量把你的布局分成两部分,然后像我们通常做的那样膨胀两个碎片。

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
             xmlns:tools="http://schemas.android.com/tools"
             android:id="@+id/frameContainer"
             android:layout_width="match_parent"
             android:layout_height="match_parent"
              android:orientation="vertical"
             tools:context="com.android.buffer.exampleapplication.MainActivity">

    <FrameLayout
        android:id="@+id/flFragment1"
        android:layout_weight="1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

      <FrameLayout
          android:id="@+id/flFragment2"
        android:layout_weight="1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

</LinearLayout>

java代码来膨胀片段。

代码语言:javascript
复制
getFragmentManager().beginTransaction().replace(R.id.flFragment1, FragmentA.getInstance(msg)).commit();
            getFragmentManager().beginTransaction().replace(R.id.flFragment2, FragmentA.getInstance(msg)).commit();
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47364226

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档