NavigationView中的视图未显示/不可见

时间:2018-02-14 08:01:22

标签: android android-layout drawerlayout navigationview android-navigationview

我使用带有抽屉布局的导航视图和侧面导航视图中的自定义布局作为菜单,并将其包含在导航视图中但注意到可见,我还尝试添加其他类型的视图但导航视图中没有显示任何内容。 下面是我正在使用drawerlayout和导航视图和主要活动类

的主要活动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"
android:id="@+id/Drawer"
tools:context="com.example.minhasoft_pc.drawer.MainActivity">

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

    <ImageView
        android:layout_margin="10dp"
        android:layout_gravity="center"
        android:src="@mipmap/ic_launcher_round"
        android:layout_weight="1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    <ImageView
        android:layout_margin="5dp"
        android:layout_gravity="center"
        android:src="@mipmap/ic_launcher_round"
        android:layout_weight="1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    <ImageView
        android:layout_margin="10dp"
        android:layout_gravity="center"
        android:src="@mipmap/ic_launcher_round"
        android:layout_weight="1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />



</LinearLayout>


<android.support.design.widget.NavigationView
    android:id="@+id/nav_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:fitsSystemWindows="true"
    android:layout_marginEnd="-65dp"
    android:layout_marginRight="-65dp"
    >

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

        <include layout="@layout/drawer_menu"/>


    </LinearLayout>



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


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

活动类

public class MainActivity extends AppCompatActivity {


private DrawerLayout mDrawerlayout ;
private ActionBarDrawerToggle mToggle;

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



   // ActionBar bar = getActionBar();
   // bar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#0000ff")));



    mDrawerlayout = (DrawerLayout) findViewById(R.id.Drawer) ;
    mToggle = new ActionBarDrawerToggle(this,mDrawerlayout,R.string.draweropen,R.string.drawerclosed) ;



    mDrawerlayout.addDrawerListener(mToggle);
    mToggle.syncState();

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {

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

    return super.onOptionsItemSelected(item);
}

}

1 个答案:

答案 0 :(得分:0)

您必须包含导航。像这样的抽屉菜单项,请检查以下xml代码作为参考:

此处包含def long_running(handler): for i in range(10): thetxt = '{0}: {1}'.format(str(datetime.now()), str(i)) sleep(1) # using this as drop-in for something which is blocking wx.CallAfter(handler, thetxt) wx.Yield() … if __name__ == '__main__': … wx.CallLater(1500, long_running, handler.update_prog) app.MainLoop()

您可以使用解决方案来引用此问题:Align custom view to left of navigation drawer

app:menu="@menu/nav_drawer_items"