更新时间:2023-02-05 21:41:38
修改<片段/>
在XML布局<的FrameLayout />
<的FrameLayout
机器人:ID =@ + ID / frag_title
机器人:能见度=水涨船高
机器人:layout_marginTop =机器人:ATTR / actionBarSize
机器人:layout_width =@扪/ titles_size
机器人:layout_height =match_parent/>
<的FrameLayout
机器人:ID =@ + ID / frag_content
机器人:layout_width =match_parent
机器人:layout_height =match_parent/>
和编程方式添加片段:
FragmentManager fragmentManager = getFragmentManager()
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
ExampleFragment片段=新ExampleFragment();
fragmentTransaction.replace(R.id.frag_content,片段);
fragmentTransaction.commit();
但在第一次读到这。
Hi I have a linearLayout containing two fragments and I add tabs with code to this layout. What I want is when I click tab1 it is ok to fragment fill itself from indicated class, but in tab2 I want to change this class to another class. Thank you
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/frags">
<fragment class="com.tugce.MitsActionBar.DoktorlarFragment"
android:id="@+id/frag_title"
android:visibility="gone"
android:layout_marginTop="?android:attr/actionBarSize"
android:layout_width="@dimen/titles_size"
android:layout_height="match_parent" />
<fragment class="com.tugce.MitsActionBar.ContentFragment"
android:id="@+id/frag_content"
android:layout_width="match_parent"
android:layout_height="match_parent" />
Change <fragment/>
in xml layout to <FrameLayout/>
<FrameLayout
android:id="@+id/frag_title"
android:visibility="gone"
android:layout_marginTop="?android:attr/actionBarSize"
android:layout_width="@dimen/titles_size"
android:layout_height="match_parent" />
<FrameLayout
android:id="@+id/frag_content"
android:layout_width="match_parent"
android:layout_height="match_parent" />
and add fragments programmatically:
FragmentManager fragmentManager = getFragmentManager()
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
ExampleFragment fragment = new ExampleFragment();
fragmentTransaction.replace(R.id.frag_content, fragment);
fragmentTransaction.commit();
But at first read this.