V
V
Vlad_Ilnitskiy2015-02-17 19:31:13
Android
Vlad_Ilnitskiy, 2015-02-17 19:31:13

How to get rid of overlapping fragments on each other?

Good afternoon. There is an android application that uses fragments. When testing on a device, the fragment is superimposed on itself.
This is the main_activity.xml code:

<?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/blow1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:baselineAligned="false"
    android:weightSum="1">
    <fragment
        android:id="@+id/blow"
        android:name="com.example.ilnitskiy.keepcalm5_final.blow"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        tools:layout="@layout/blow">
    </fragment>
</LinearLayout>

This is the snippet code, blow.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:id="@+id/blow"
    android:weightSum="1"
    android:visibility="visible">
    <TextView
        android:id="@+id/textView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/p"
        android:layout_weight="0.09"
        android:textSize="40sp"
        android:visibility="visible">
    </TextView>
    <Button
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:text="@string/stop"
        android:id="@+id/button"
        android:layout_gravity="right"
        android:layout_weight="0.09"
        android:onClick="onClick"
        android:visibility="visible" />
</LinearLayout>

Here is the code at the beginning of main_activity.java
public class MainActivity extends FragmentActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Fragment frag = new blow();
        FragmentTransaction ft = getFragmentManager().beginTransaction();
        ft.replace(R.id.blow, frag);
        ft.commit();
    }

Here's how it should look: 99a12b60a9534c0bb7b13b1c895ed2f9.JPG
And here's how it looks on a real device:
7210fd4212b744189cc4fdb39cf87c8f.png
Sorry for the excess of information, I just don't know where to look for the problem.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Oleg Gamega, 2015-02-17
@Vlad_Ilnitskiy

replace main_activity fragment with FrameLayout

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question