@Vlad_Ilnitskiy

Как избавиться от наложения фрагментов друг на друга?

Добрый день. Есть android приложение, в котором используются фрагменты. При тестировании на устройстве фрагмент накладывается на себя же.
Это код main_activity.xml:
<?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>

Это код фрагмента, 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>


Вот код в начале 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();
    }


Вот как все должно выглядеть:99a12b60a9534c0bb7b13b1c895ed2f9.JPG

А вот как все выглядит на реальном устройстве:
7210fd4212b744189cc4fdb39cf87c8f.png

Простите за избыток информации, просто уже не знаю где искать проблему.
  • Вопрос задан
  • 3942 просмотра
Решения вопроса 2
gadfi
@gadfi
https://gamega.org
замени в main_activity fragment на FrameLayout
Ответ написан
Комментировать
@Vlad_Ilnitskiy Автор вопроса
Ошибка выяснилась: во фрагменте использовал не android.support.v4.app.Fragment, а android.app.Fragment, в итоге он вызывал сам себя.
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы