Android: Fragments Overlapping Issue

Android: fragments overlapping issue

Just set a background color to your <fragment /> in XML file.

Solves the issue.

Fragment overlapping one on another in android

Your second fragment's parent layout must have a background.

PlayQuizSubjectWise XML

<RelativeLayout 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"
android:background="#FFF" //Here
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin" >

fragment overlapping and activity

add this android:background="@android:color/holo_red_dark" in your fragment layout

Problem replacing Fragment within another one. (fragments overlapping)

I had to change background color of SaveRouteFragment to e.g. white.

Fragment overlapping each other...and previous fragment is clicking

You're using fragmentTransaction.add(), which won't remove the previous Fragment - use fragmentTransaction.replace() if you want the other Fragment's view to be removed.

Note FragmentManager automatically restores any previously added Fragments when your Activity is recreated (i.e., when savedInstanceState != null). Therefore you'll want to ensure that you only add your initial Fragment once - when the savedInstanceState is null.

if (savedInstanceState == null) {
loadFragment(new FragmentRegLogSkip(), FragmentRegLogSkip.FRAGMENT_KEY);
}

Android Fragments Overlapping

SOLVED:

The problem was that I was adding the TextView to the fragment's container (a FrameLayout), I solved it adding the TextView to the Fragmet's Layout and dynamically changing its text.

The Code:

Fragment:

public class ViewMessageFragment extends Fragment
{
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState)
{
//Get the message
String message = getArguments().getString(MainActivity.EXTRA_MESSAGE);

//Inflate the layout in a View. This way you get the fragments layout
View mContainer = inflater.inflate(R.layout.fragment_view_message, container, false);

//Find the TextView contained in the fragments Layout and change its message
TextView textView = (TextView) mContainer.findViewById(R.id.show_message);
textView.setText(message);

//Return the layout
return mContainer;
}

Fragment's Layout:

<?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" >

<TextView android:id="@+id/show_message"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:textSize="20sp"
android:textIsSelectable="true"/>

</LinearLayout>


Related Topics



Leave a reply



Submit