Estou usando fragments ao invés de activity, só que quando eu chamo o segundo fragment com o método replace, ele não sobrepõe completamente o fragment anterior, ele fica por cima, mas o desenho do outro fragment continua aparecendo, como faço para que isso não aconteça ?
código xml da primeira tela
<?xml version="1.0" encoding="utf-8"?>
<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:id="@+id/frame_layout"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="br.com.demmy.demet.gerador.MainActivity"
tools:showIn="@layout/app_bar_main">
<fragment
android:id="@+id/primeiro_fragment"
android:name="br.com.demmy.demet.gerador.PrimeiroFragment"
android:layout_width="match_parent"
android:layout_height="match_parent">
</fragment>
</FrameLayout>
Código do primeirofragment.java
public class PrimeiroFragment extends Fragment {
View minha_view;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
minha_view = inflater.inflate(R.layout.tela_principal, container, false);
return minha_view;
}
}
código da tela principal.xml
<?xml version="1.0" encoding="utf-8"?>
<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:id="@+id/frame_layout"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="br.com.demmy.demet.gerador.MainActivity"
tools:showIn="@layout/app_bar_main">
<LinearLayout
android:id="@+id/linear_layout"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<TextView
android:id="@+id/textView_hora"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:textSize="18sp"
android:text="texto1" />
<EditText
android:id="@+id/editText_hora"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/oval"
android:padding="8dp"
android:layout_margin="8dp"
android:ems="4"
android:inputType="number" />
<TextView
android:id="@+id/textView3"
android:layout_gravity="center"
android:textSize="18sp"
android:layout_marginTop="3dp"
android:layout_marginBottom="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Texto 2" />
<EditText
android:id="@+id/texto_notification"
android:padding="14dp"
android:gravity="start"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_margin="8dp"
android:layout_weight="1"
android:background="@drawable/oval"
android:inputType="textMultiLine" />
<Button
android:id="@+id/button"
style="@style/estilo_botao"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
android:text="Cadastrar" />
</LinearLayout>
</FrameLayout>
Código do segundofragment.java
public class SegundoFragment extends Fragment {
View minha_view;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
minha_view = inflater.inflate(R.layout.segundo_layout, container, false);
return minha_view;
}
}
código do segundo_layout.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">
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="138dp"
android:layout_marginStart="138dp"
android:layout_marginTop="196dp"
android:text="SEGUNDO LAYOUT" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignTop="@+id/textView2"
android:layout_marginLeft="68dp"
android:layout_marginStart="68dp"
android:text="Button" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="@+id/textView2"
android:layout_alignRight="@+id/textView2"
android:layout_below="@+id/button2"
android:layout_marginTop="16dp"
android:text="Button" />
<Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/button3"
android:layout_alignParentTop="true"
android:layout_alignStart="@+id/button3"
android:layout_marginLeft="17dp"
android:layout_marginStart="17dp"
android:layout_marginTop="60dp"
android:text="Button" />
<Button
android:id="@+id/button5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignTop="@+id/textView2"
android:text="Button" />
</RelativeLayout>
código que está chamando os fragments
lista_drawer.setOnItemClickListener(new AdapterView.OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
android.app.FragmentManager fragmentManager = getFragmentManager();
if (position == 0){
fragmentManager.beginTransaction().replace(R.id.frame_layout, new PrimeiroFragment()).commit();
}else if(position == 1){
fragmentManager.beginTransaction().replace(R.id.frame_layout, new SegundoFragment()).commit();
}else if(position == 2){
fragmentManager.beginTransaction().replace(R.id.frame_layout, new TerceiroFragment()).commit();
}
}
});
android:background="@android:color/white"
noRelativeLayout
do segundo fragment pode resolver este problema.android:clickable="true"
no layout do segundo fragment os componentes do primeiro fragment não serão clicáveis pelo menos.