每当我点击Receive消息时,它就会转到ReceivedFragment,它可以工作,但问题是Mainactivity与ReceivedFragment重叠,正如您在下面的图像中看到的,我已经尝试删除framelayout中的所有视图,但结果总是一样,有人能帮我吗? 我是安卓新手,下面是我现在的代码,谢谢
MainActivty.java
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
switch (i) {
case 0:
break;
case 1:
ReceivedFragment dashfragment = new ReceivedFragment();
FrameLayout fl = (FrameLayout) findViewById(R.id.frame_layout);
fl.removeAllViews();
FragmentTransaction transaction1 =getSupportFragmentManager().beginTransaction();
transaction1.add(R.id.frame_layout, dashfragment);
transaction1.commit();
break;
//case - so on and so on
我的Activity.xml
<?xml version="1.0" encoding="utf-8"?>
<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"
tools:context=".MainActivity"
>
<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/frame_layout" />
</RelativeLayout >
在onCreate()
方法中引用ListView
。
listView = findViewById(R.id.listView);
在OnItemClick
方法中:
listView.setVisibility(View.INVISIBLE);
返回时使其再次可见:
listView.setVisibility(View.VISIBLE);