I am trying to add a lot of Frame Layout to activity. It looks like:
photo1
photo2
How much will appear on the screen depends on the screen resolution so I would like to add over a dozen fragments and make activity scrollable. I want it to look like list view. For now I have a few Frame Layout and adds fragments one by one. If anyone has an idea how to do it, please help me. Thanks.
FragmentManager fragmentManager = getSupportFragmentManager();
Fragment s1 = new SingleCourseFragment();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
FrameLayout container = findViewById(R.id.fragmentContainer);
fragmentTransaction.add(R.id.fragmentContainer, s1);
fragmentTransaction.commit();
Fragment s2 = new SingleCourseFragment();
FragmentTransaction fragmentTransaction2 = fragmentManager.beginTransaction();
fragmentTransaction2.add(R.id.fragmentContainer2, s2);
fragmentTransaction2.commit();
FrameLayout container2 = findViewById(R.id.fragmentContainer2);
Fragment s3 = new SingleCourseFragment();
FragmentTransaction fragmentTransaction3 = fragmentManager.beginTransaction();
fragmentTransaction3.add(R.id.fragmentContainer3, s3);
fragmentTransaction3.commit();
FrameLayout container3 = findViewById(R.id.fragmentContainer3);
Fragment s4 = new SingleCourseFragment();
FragmentTransaction fragmentTransaction4 = fragmentManager.beginTransaction();
fragmentTransaction4.add(R.id.fragmentContainer4, s4);
fragmentTransaction4.commit();
FrameLayout container4 = findViewById(R.id.fragmentContainer4);
container.setVisibility(View.VISIBLE);
container2.setVisibility(View.VISIBLE);
container3.setVisibility(View.VISIBLE);
container4.setVisibility(View.VISIBLE);
XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context=".MainActivity"
tools:showIn="#layout/activity_main">
<EditText
android:id="#+id/startET"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:inputType="text"
android:layout_margin="20dp"
android:enabled="false"
android:gravity="center"
android:background="#drawable/rounded_border_edittext"
android:hint="#string/start"/>
<EditText
android:id="#+id/endET"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_alignParentStart="true"
android:layout_below="#+id/startET"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="20dp"
android:enabled="false"
android:gravity="center"
android:background="#drawable/rounded_border_edittext"
android:inputType="text"/>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/fragmentContainer"
android:layout_below="#+id/endET"
android:visibility="invisible">
</FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/fragmentContainer2"
android:layout_below="#+id/fragmentContainer"
android:visibility="invisible">
</FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/fragmentContainer3"
android:layout_below="#+id/fragmentContainer2"
android:visibility="invisible">
</FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/fragmentContainer4"
android:layout_below="#+id/fragmentContainer3"
android:visibility="invisible">
</FrameLayout>
</RelativeLayout>
If I understood correctly, you just want to make your layout scrollable.
You can make the top-level layout a ScrollView as below
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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:fillViewport="true">
<!-- Then put your layout here as such-->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context=".MainActivity"
tools:showIn="#layout/activity_main">
<!-- other widgets in your layout -->
</RelativeLayout>
</ScrollView>
Update
You could try adding in the xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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:fillViewport="true">
<!-- Add a linear layout-->
<LinearLayout
android:id="#+id/list_of_frags"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
</LinearLayout>
</ScrollView>
Or
//Begin the transaction
LinearLayout layout = (LinearLayout)findViewById(R.id.list_of_frags);
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
//You can create an array with the container
ArrayList<int> listOfContainers = ArrayList<int>()
listOfContainers.add(R.id.fragmentContainer1)
listOfContainers.add(R.id.fragmentContainer2)
listOfContainers.add(R.id.fragmentContainer3)
listOfContainers.add(R.id.fragmentContainer4)
Int AmountOfFragments = 4
//Replace the contents of the container with the new fragmentTest
for (int i = 0; i < AmountOfFragments; i++){
//Or You can create the FrameLayout programmatically as below
FrameLayout frame = new FrameLayout(this);
frame.setId(i);
layout.addView(frame);
ft.add(i, new SingleCourseFragment());
//if you do the above you don't need this line
ft.add(listOfContainers[i], new SingleCourseFragment());
}
//Complete the changes
ft.commit();
Related
I'm trying to make a bottomNavigation that goes between the main activity, and two fragments. Right now I went after a tutorial and created a third fragment:
Here's the bottomNavigation listener:
private BottomNavigationView.OnNavigationItemSelectedListener bottom_navigation_listener =
new BottomNavigationView.OnNavigationItemSelectedListener() {
#Override
public boolean onNavigationItemSelected(#NonNull MenuItem item) {
switch (item.getItemId())
{
case R.id.Piano:
setTitle("Pitch Piano");
PianoFragment fragment = new PianoFragment();
android.support.v4.app.FragmentTransaction fragmentTransaction1 = getSupportFragmentManager().beginTransaction();
fragmentTransaction1.replace(R.id.frame, fragment, "Piano");
fragmentTransaction1.commit();
return true;
case R.id.Rhythm:
setTitle("Rhythm");
Rhythm fragment2 = new Rhythm();
android.support.v4.app.FragmentTransaction fragmentTransaction2 = getSupportFragmentManager().beginTransaction();
fragmentTransaction2.replace(R.id.frame, fragment2, "Rhythm");
fragmentTransaction2.commit();
return true;
case R.id.Intervals:
setTitle("Intervals and Chords");
Intervals_and_chords fragment3 = new Intervals_and_chords();
android.support.v4.app.FragmentTransaction fragmentTransaction3 = getSupportFragmentManager().beginTransaction();
fragmentTransaction3.replace(R.id.frame, fragment3, "Intervals");
fragmentTransaction3.commit();
return true;
}
return false;
}
};
Main Activity layout (shortened):
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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"
tools:context="com.stefanawesome.piano.MainActivity">
<RelativeLayout
android:layout_width="581dp"
android:layout_height="503dp"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:background="#ffffff"
android:id="#+id/lin_lay"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.031"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintHorizontal_bias="0.5"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp">
<include
android:id="#+id/toolbar"
layout="#layout/tool_bar"
/>
<android.support.design.widget.BottomNavigationView
android:id="#+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/upperback"
android:layout_alignStart="#+id/upperback"
android:layout_below="#+id/myRectangleView"
app:itemBackground="#color/bottomNavView"
app:itemIconTint="#drawable/bottomnavbutton"
app:itemTextColor="#drawable/bottomnavbutton"
app:menu="#menu/bottom_nav_items" />
<FrameLayout
android:id="#+id/frame"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
Rhythm Fragment layout:
<FrameLayout 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"
tools:context="com.stefanawesome.piano.Rhythm">
<!-- TODO: Update blank fragment layout -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
android:id="#+id/toolbar"
layout="#layout/rhythmtoolbar"
/>
</RelativeLayout>
</FrameLayout>
Interval Fragment layout:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.stefanawesome.piano.Intervals_and_chords">
<!-- TODO: Update blank fragment layout -->
</FrameLayout>
Screenshot when the bottom nav bar is on the rhythm section:
Instead of jumping between the main activity, and then the two fragments, the main activity layout never goes away, even if you go to one of the fragments, the fragment layout is behind the main layout.
Also, if I added code in any of the fragments, the program crashes.
hi I have a problem in this line I do not know why
FragmentManager manager = getFragmentManager();
FragmentTransaction trans = manager.beginTransaction();
trans.replace(R.id.containerr,new FragmentLastComments());
trans.commit();
xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/containerr"
android:layoutDirection="ltr">
</RelativeLayout>
fragment xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layoutDirection="ltr">
<LinearLayout
android:id="#+id/linearLayout3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginTop="55dp"
android:orientation="vertical">
<TextView
android:id="#+id/txt_lastcomments"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:textSize="20dp"
android:layout_marginBottom="10dp"
android:text="last comments" />
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginRight="5dp"
android:layout_marginLeft="5dp"
android:id="#+id/rv_lastcomments"/>
</LinearLayout>
</RelativeLayout>
this line is not working
trans.replace(R.id.containerr,new FragmentLastComments());
When I remove this line I'm not getting any problem but when I'm using this line I'm getting problem I think the problem here
R.id.containerr
I hope someone will help me to solve this
Try this way,
FragmentManager mFragmentManager=getFragmentManager();
Fragment mfragment = new FragmentLastComments();
mFragmentManager
.beginTransaction()
.replace(R.id.rl_main_new, fragmentDash, "tag")
.commit();
I hope this helps you.
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.add(R.id.frame_aaron, fragment);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
Put your fragment inside a FrameLayout like this :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/containerr"
android:layoutDirection="ltr">
<FrameLayout
android:id="#+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
And change your Fragment method with this :
FragmentManager manager = getFragmentManager();
FragmentTransaction trans = manager.beginTransaction();
trans.replace(R.id.fragment_container,new FragmentLastComments());
trans.commit();
I have one activity (Navigation Controller) that controls multiple fragments. The initial screen the user sees is a single fragment placed into one container. When I click a button to a different fragment I need to add the first fragment to the backstack and add the two new fragments to different containers than the first one. The two fragments are a map fragment on top and a profile details fragment on the bottom Is this even possible?
The code is below.
Navigation Controller Home Fragment (this is the main screen when the app starts):
public void home(Bundle savedInstanceState){
FragmentManager fm = getFragmentManager();
FragmentTransaction fragmentTransaction = fm.beginTransaction();
if (findViewById(R.id.fragment_container) != null) {
if (savedInstanceState != null) {
return;
}
// Create a new Fragment to be placed in the activity layout
CurrentFriendsFragment firstFragment = new CurrentFriendsFragment();
// Add the fragment to the 'fragment_container' FrameLayout
fragmentTransaction
.setCustomAnimations(R.animator.fade_in, R.animator.fade_out)
.replace(R.id.fragment_container, firstFragment, "firstFragment")
.commit();
}
}
Navigation Controller Profile Fragment:
#Override
public void onProfileButtonClicked() {
FragmentManager fm = getFragmentManager();
FragmentTransaction fragmentTransaction = fm.beginTransaction();
if (findViewById(R.id.fragment_container) != null) {
if (savedInstanceState1 != null) {
return;
}
MapFragment mapFragment = new MapFragment();
// Create a new Fragment to be placed in the activity layout
ProfileFragment profileFragment = new ProfileFragment();
// Add the fragment to the 'fragment_container' FrameLayout
fragmentTransaction
.setCustomAnimations(R.animator.slide_in_up, R.animator.slide_out_up, R.animator.slide_in_down, R.animator.slide_out_down)
.add(R.id.fragment_container_bottom_large, profileFragment)
.add(R.id.fragment_container_top_small, mapFragment)
.commit();
}
}
And here is the main activities xml file. Note the three different containers. "fragment_container" for full screen fragments, and "fragment_container_top_small", "fragment_container_bottom_large" for multiple fragments on one page.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:id="#+id/activity_navigation"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.parse.starter.ViewControllers.NavigationController"
android:background="#color/palette_darkwhite">
<include layout="#layout/tool_bar"
android:id="#+id/toolbar_layout" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_below="#+id/toolbar_layout"
android:layout_above="#+id/bottom_navigation_navbar">
<RelativeLayout
android:id="#+id/fragment_container_top_small"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
</RelativeLayout>
<FrameLayout
android:id="#+id/fragment_container_bottom_large"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="3">
</FrameLayout>
</LinearLayout>
<FrameLayout
android:id="#+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/toolbar_layout"
android:layout_above="#+id/bottom_navigation_navbar">
</FrameLayout>
<FrameLayout
android:id="#+id/fragment_container_popup"
android:layout_width="275dp"
android:layout_height="275dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true">
</FrameLayout>
<android.support.design.widget.BottomNavigationView
android:id="#+id/bottom_navigation_navbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#color/palette_lightwhite">
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_gravity="center_horizontal"
android:background="#null"
app:srcCompat="#drawable/collpaseup" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical">
<LinearLayout android:id="#+id/thumbnail2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dp"
android:layout_alignParentLeft="true"
android:layout_marginRight="5dp">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/profile_picture_navbar"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="center_vertical"
app:civ_border_color="#FF000000"/>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/thumbnail2"
android:layout_toRightOf="#+id/thumbnail2"
android:textColor="#color/palette_primarycolor"
android:id="#+id/nameLabel"
android:text="Name"
android:textSize="15sp"
android:textStyle="bold"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/nameLabel"
android:layout_toRightOf="#+id/thumbnail2"
android:textColor="#color/palette_primarycolor"
android:id="#+id/locationLabel"
android:text="Location"
android:textSize="12sp"
android:textStyle="bold"/>
</RelativeLayout>
</android.support.design.widget.BottomNavigationView>
</RelativeLayout>
Have 3 containers and use View.GONE to make the 1st disappear and then View.VISIBLE to make the other 2 appear.
I am trying to create a swappable fragements on my android app
Only half the part of fragment seems to be replacing
screenshot:
The xml file for the main is
<?xml version="1.0" encoding="utf-8"?>
<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:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:showIn="#layout/app_bar_main"
tools:context=".MainActivity"
android:id="#+id/contentlayout">
<fragment
android:layout_width="match_parent"
android:layout_height="60dp"
android:id="#+id/header_menufragment"
class="com.example.www.newapp.header_menu" />
<fragment
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/dynamicfragment"
class="com.example.www.newapp.mainfragment"/>
</LinearLayout>
the whole dynamicfragment is supposed to be replaced by projectfragment on click of Project button.
project.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
getFragmentManager()
.beginTransaction()
.replace(R.id.dynamicfragment, new projectfragment())
.addToBackStack(null)
.commit();
}
});
the projectfragment class has
public class projectfragment extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_project, container,false);
}
}
the layout file is
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:background="#color/colorDarkRed">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:layout_weight=".5">
<ImageButton
android:id="#+id/img1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1" />
<ImageButton
android:id="#+id/img2"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1" />
</LinearLayout>
<ImageButton
android:id="#+id/img3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:src="#drawable/imgfile"/>
</LinearLayout>
Kindly help me solve this issue.
You cannot replace a fragment defined statically in the layout file. You can only replace fragments that you added dynamically via a FragmentTransaction.
Use FrameLayout as container and replace Fragment inside that.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent" android:layout_height="match_parent">
<FrameLayout android:id="#+id/fragment_container" android:layout_weight="1"
android:layout_width="match_parent" android:layout_height="match_parent" />
</LinearLayout>
On Activity add Fragment same as you do:
getFragmentManager()
.beginTransaction()
.replace(R.id.fragment_container, new projectfragment())
.addToBackStack(null)
.commit();
For more info refer below link:
link1
link2
that worked for me try this way
WishaFriend ff = new WishaFriend();
android.app.FragmentManager fm = getActivity().getFragmentManager();
android.app.FragmentTransaction ft = fm.beginTransaction();
ft.replace(((ViewGroup) getView().getParent()).getId(), ff);
ft.commit();
dialog.dismiss();
try add this
ft.replace(((ViewGroup) getView().getParent()).getId(), ff);
I am trying to make an activity containing two fragments.The first one has 3 nested fragments which I will use as a tabs and the second one only contains buttons. I don't want to add the buttons fragment into other fragments because I don't want it to reload. Right now i don't have any errors but my buttons fragment doesn't show up. Here are my fragments and my activity.
my main activity:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
setContentView(R.layout.activity_main);
Fragment statistics = new StatisticsFragment();
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.add(R.id.fragment_statistics, statistics).commit();
Fragment buttons = new MainPageButtonsFragment();
FragmentTransaction buttonsTransaction = getSupportFragmentManager().beginTransaction();
buttonsTransaction.add(R.id.main_page_buttons_fragment,buttons).commit();
his layout
<RelativeLayout android:orientation="vertical" >
<FrameLayout
android:id="#+id/fragment_statistics"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="#+id/main_page_buttons_fragment"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/fragment_statistics"/>
I wont write my buttons fragment because it is not necessary I will only say its root tag is FrameLayout.
my statistics fragment (the one with tabs)
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Fragment currentDayFragment = new CurrentDayFragment();
FragmentTransaction transaction1 = getChildFragmentManager().beginTransaction();
transaction1.add(R.id.current_day_fragment, currentDayFragment).commit();
Fragment configurationInfoFragment = new ConfigurationInfoFragment();
FragmentTransaction transaction2 = getChildFragmentManager().beginTransaction();
transaction2.add(R.id.configuration_info_fragment, configurationInfoFragment).commit();
Fragment expensesInfoFragment = new ExpensesInfoFragment();
FragmentTransaction transaction3 = getChildFragmentManager().beginTransaction();
transaction3.add(R.id.expenses_info_fragment, expensesInfoFragment).commit();
LayoutInflater lf = getActivity().getLayoutInflater();
View statisticsView = lf.inflate(R.layout.fragment_statistics, container, false);
return statisticsView;
}
his layout:
<FrameLayout >
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="#id/current_day_fragment"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="#id/configuration_info_fragment"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="#id/expenses_info_fragment"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</android.support.v4.view.ViewPager>
the nested fragments just have root tag FrameLayout and couple of TextViews in it. The result is just an activity with 3 tabs and no buttons fragment.
I am new to android programming and I am completely lost in this. Help Please!
Try using giving custom height like this....
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<FrameLayout
android:id="#+id/fragment_statistics"
android:layout_width="fill_parent"
android:layout_height="250dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<FrameLayout
android:id="#+id/main_page_buttons_fragment"
android:layout_width="fill_parent"
android:layout_height="250dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true" />
</RelativeLayout>
Relative layout does not have android:orientation param
I thing first fragment cover second one
Change relative layout with LinearLayout
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="#+id/fragment_statistics"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="#+id/main_page_buttons_fragment"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/fragment_statistics"/>
</LinearLayout>