Android导航抽屉是透明的,与ListView重叠

时间:2017-11-12 06:52:17

标签: android listview android-fragments

enter image description here

enter image description here

如图所示,我在同一个活动中使用DrawerLayout和TabLayout。因此,屏幕基本上是TabLayout的ViewPager(片段标签)。当我打开导航抽屉时,它会重叠,如图所示。

我已经在Android NavigationDrawer transparency尝试了解决方案 (与此问题有同样的问题)

但它没有用。

我也尝试将android:alpha="255"添加到ListView,但没有用。

以下是我的代码:

MainActivity.java

public class UserMainActivity extends AppCompatActivity {

    private DrawerLayout mDrawerLayout;
    private ActionBarDrawerToggle mToggle;

    private SectionsPageAdapter pageAdapter;

    ViewPager viewPager;

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

        FragmentManager fragmentManager = getSupportFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        fragmentTransaction.replace(R.id.container, new MatchListTab());

        mDrawerLayout = (DrawerLayout) findViewById(R.id.nav_layout);

        mToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.navigation_drawer_open, R.string.navigation_drawer_close);

        mDrawerLayout.addDrawerListener(mToggle);
        mToggle.syncState();

        getSupportActionBar().setDisplayHomeAsUpEnabled(true);

        pageAdapter = new SectionsPageAdapter(getSupportFragmentManager());

        viewPager = (ViewPager) findViewById(R.id.container);
        setupViewPager(viewPager);

        TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
        tabLayout.setupWithViewPager((viewPager));


    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {

        if(mToggle.onOptionsItemSelected(item)) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    // Adds fragments to SectionsPageAdapter and gives names for the corresponding tab

    private void setupViewPager(ViewPager viewPager) {
        SectionsPageAdapter adapter = new SectionsPageAdapter(getSupportFragmentManager());
        adapter.addFragment(new MatchListTab(), "Scores");
        adapter.addFragment(new MatchListTab(), "Live");
        adapter.addFragment(new MatchListTab(), "Favorite");
        adapter.addFragment(new MatchListTab(), "Data");
        viewPager.setAdapter(adapter);
    }
}

activity_main.xml中

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout 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:layout_height="match_parent"
    tools:context="ykim164cs242.tournamentor.UserMainActivity"
    android:id="@+id/nav_layout">

    <android.support.design.widget.NavigationView
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="#5555"
        app:headerLayout="@layout/navigation_header"
        app:menu="@menu/navigation_menu">

    </android.support.design.widget.NavigationView>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <android.support.v4.view.ViewPager
            android:id="@+id/container"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="3.18"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"
            />

        <android.support.design.widget.AppBarLayout
            android:id="@+id/appbar"
            android:layout_width="match_parent"
            android:layout_height="71dp">

            <android.support.design.widget.TabLayout
                android:id="@+id/tabs"
                android:layout_width="match_parent"
                android:layout_height="71dp"
                app:tabIndicatorColor="@android:color/holo_orange_dark" />

        </android.support.design.widget.AppBarLayout>
    </LinearLayout>

</android.support.v4.widget.DrawerLayout>

list.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ListView
        android:id="@+id/match_list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:alpha="255"/>

</LinearLayout>

我该如何解决这个问题?

0 个答案:

没有答案