1

MainActivity에는 2 개의 버튼이 있습니다. 버튼을 클릭하면 2 개의 프래그먼트가 동일한 page.But에 표시되기를 원합니다.하지만 ContactContact 버튼을 클릭하면 표시되지만 PhoneContact 버튼을 클릭하면 다른 하나를 덮어 씁니다.Android 조각이 오버 헤드를 보입니다

MainActivity.java

public class MainActivity extends AppCompatActivity { 

Button itsMeContact,phoneContact; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 



    itsMeContact= (Button) findViewById(R.id.its_me_contact); 
    phoneContact= (Button) findViewById(R.id.phone_contact); 

    itsMeContact.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 

      FragmentManager manager = getFragmentManager(); 
      UserFragment userFragment = new UserFragment(); 
      FragmentTransaction transaction = manager.beginTransaction(); 
      transaction.add(R.id.frame_layout, userFragment, "userFragment"); 

      transaction.commit(); 
     } 
    }); 

    phoneContact.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      FragmentManager manager = getFragmentManager(); 
      FragmentB fragmentB = new FragmentB(); 
      FragmentTransaction transaction = manager.beginTransaction(); 
      transaction.add(R.id.frame_layout, fragmentB, "fragg"); 

      transaction.commit(); 
     } 
    }); 

} 

} 

UserFragment.java

public class UserFragment extends Fragment { 
RecyclerView recyclerView ; 
UserAdapter userAdapter ; 
ArrayList<Person> arrayList ; 
private LinearLayoutManager layoutManager; 
Button itsMeContact,phoneContact; 

@Nullable 
@Override 
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) { 
    View view=inflater.inflate(R.layout.fragment_user,container,false); 


    recyclerView = view.findViewById(R.id.recycler_view); 
    itsMeContact= view.findViewById(R.id.its_me_contact); 


    layoutManager = new LinearLayoutManager(getActivity()); 
    layoutManager.scrollToPosition(0); 
    layoutManager.setOrientation(LinearLayoutManager.VERTICAL); 
    recyclerView.setLayoutManager(layoutManager); 
    arrayList=new ArrayList<Person>(); 

    initial(); 

    return view; 
} 

private void initial() { 
    Factory.getInstance().user().enqueue(new Callback<List<User>>() { 
     @Override 
     public void onResponse(Call<List<User>> call, Response<List<User>> response) { 
      // textView.setText(response.body().get(0).name); 
      userAdapter= new UserAdapter(response.body(), getActivity()); 
      recyclerView.setAdapter(userAdapter); 

     } 

     @Override 
     public void onFailure(Call<List<User>> call, Throwable t) { 

     } 
    }); 

} 

} 

FragmentB.java

public class FragmentB extends Fragment { 
TextView textView; 

@Nullable 
@Override 
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) { 
    View view=inflater.inflate(R.layout.fragment_fragment_b,container,false); 
    textView=view.findViewById(R.id.textView); 
    textView.setText("naber"); 

    return view; 
} 

}

나를 위해 중요한 당신의 조언!

당신에게 대단히 감사합니다

내 애플 : enter image description here

답변

0

같은 FrameLayout이 사용했던 각 조각 트랜잭션 : "R.id.frame_layout을".

"정상적으로 보입니다"라는 말은 정상적인 현상입니다. 2 개의 단편을 동일한 레이아웃으로 표시하려면 2 개의 다른 프레임을 사용해야합니다.