【问题标题】:Navigation drawer view xml file导航抽屉视图 xml 文件
【发布时间】:2017-02-08 04:57:26
【问题描述】:

在我的地方订单活动导航抽屉不是从设备屏幕的顶部开始,如您在模拟器的屏幕截图中所见。

这是我在其中实现导航抽屉的 xml 文件。

<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/drawer_layout"
tools:context="com.e_prints.myapplication.PlaceOrder">


<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/nav_container"
    >

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentBottom="true">
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/container"
            android:paddingBottom="@dimen/activity_vertical_margin"
            android:paddingLeft="@dimen/activity_horizontal_margin"
            android:paddingRight="@dimen/activity_horizontal_margin"
            android:paddingTop="@dimen/activity_vertical_margin"
            >

            <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:id="@+id/t_placeorder"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent">
                <TableRow>
                    <TextView
                        android:id="@+id/tv_psize"
                        android:text="@string/p_size"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="20dp"
                        android:layout_column="1"
                        />

                    <Spinner
                        android:layout_width="200dp"
                        android:layout_height="wrap_content"
                        android:id="@+id/size"
                        android:entries="@array/paper_size"
                        android:layout_marginTop="20dp"
                        android:layout_marginLeft="20dp"
                        android:spinnerMode="dropdown"
                        android:layout_column="1" />
                </TableRow>

                <TableRow>
                    <TextView
                        android:id="@+id/tv_pcolor"
                        android:layout_width="wrap_content"
                        android:text="@string/p_color"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="20dp"
                        android:layout_column="1"
                        />
                    <Spinner
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:entries="@array/color"
                        android:id="@+id/color"
                        android:layout_column="2"
                        android:layout_marginLeft="20dp"
                        android:layout_marginTop="20dp"></Spinner>
                </TableRow>

                <TableRow>
                    <TextView
                        android:id="@+id/tv_pbinding"
                        android:layout_width="wrap_content"
                        android:text="@string/p_binding"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="20dp"

                        android:layout_column="1"/>
                    <Spinner
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:id="@+id/binding"
                        android:entries="@array/binding"
                        android:layout_column="2"
                        android:layout_marginLeft="20dp"
                        android:layout_marginTop="20dp"

                        ></Spinner>
                </TableRow>
                <TableRow>
                    <TextView
                        android:id="@+id/tv_ptype"
                        android:layout_width="wrap_content"
                        android:text="@string/p_type"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="20dp"
                        android:layout_column="1"/>
                    <Spinner
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:id="@+id/type"
                        android:entries="@array/type"
                        android:layout_column="2"
                        android:layout_marginLeft="20dp"
                        android:layout_marginTop="20dp"
                        ></Spinner>
                </TableRow>

                <TableRow>
                    <TextView
                        android:id="@+id/tv_pattach"
                        android:layout_width="wrap_content"
                        android:text="@string/p_attach"
                        android:layout_height="wrap_content"
                        android:layout_column="1"
                        android:layout_marginTop="20dp"
                        />

                    <Button
                        android:id="@+id/b_browse"
                        android:layout_width="wrap_content"
                        android:layout_height="40dp"
                        android:background="@color/colorPrimary"
                        android:textColor="@color/white"
                        android:text="@string/b_browse"
                        android:layout_column="2"
                        android:layout_marginLeft="20dp"
                        android:layout_marginTop="20dp"
                        />
                </TableRow>
                <TableRow>
                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_below="@+id/selected"
                        android:layout_marginLeft="20dp"
                        android:layout_marginTop="20dp"
                        android:id="@+id/file_path"
                        android:text="@string/file_path"
                        android:layout_column="2"
                        />

                </TableRow>
                <TableRow>
                    <TextView
                        android:id="@+id/tv_pncpoies"
                        android:layout_width="wrap_content"
                        android:text="@string/p_copies"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="20dp"
                        android:layout_column="1"
                        />
                    <EditText
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:id="@+id/et_ncpoies"
                        android:hint="@string/p_ncopies"
                        android:layout_column="2"
                        android:layout_marginLeft="20dp"
                        android:layout_marginTop="20dp"
                        />
                </TableRow>
                <TableRow>
                    <TextView
                        android:id="@+id/tv_ppgnum"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="@string/pgnum"
                        android:layout_marginTop="20dp"
                        android:layout_column="1"
                        />
                    <RadioGroup
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="20dp"
                        android:orientation="vertical"
                        android:id="@+id/radiogroup1"
                        android:layout_column="2"
                        android:layout_marginLeft="20dp"

                        >
                        <RadioButton
                            android:text="@string/Poption1"
                            android:id="@+id/rb_poption1"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            />
                        <RadioButton
                            android:text="@string/poption2"
                            android:id="@+id/rb_poption2"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            />
                    </RadioGroup>

                </TableRow>
                <TableRow>
                    <EditText
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:id="@+id/custom_print"
                        android:hint="1-30,50,55,60-90,100"
                        android:layout_column="2"
                        android:layout_marginLeft="20dp"
                        android:visibility="invisible"
                        />



                </TableRow>
            </TableLayout>

            <RadioGroup
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/t_placeorder"
                android:layout_marginTop="20dp"
                android:orientation="horizontal"
                android:id="@+id/radiogroup">
                <RadioButton
                    android:text="@string/p_homed"
                    android:id="@+id/rb_home"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:onClick="onRadioButtonClicked"/>
                <RadioButton
                    android:text="@string/pickup"
                    android:id="@+id/rb_pick"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:onClick="onRadioButtonClicked"
                    android:layout_marginLeft="50dp"
                    />
            </RadioGroup>
            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/address"
                android:orientation="vertical"
                android:layout_marginTop="20dp"
                android:layout_below="@+id/radiogroup"
                >

            </LinearLayout>

            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="@string/b_proceed"
                android:id="@+id/b_proceed"
                android:layout_below="@id/address"
                android:layout_marginTop="20dp"
                android:background="@color/colorPrimary"
                android:textColor="@color/white"
                android:onClick="OnOrder"


                />


        </RelativeLayout>

    </ScrollView>


</FrameLayout>
<android.support.design.widget.NavigationView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:menu="@menu/nav_menu"
    android:id="@+id/navigatiom_view"
    android:layout_gravity="start"
    android:fitsSystemWindows="true"
    app:headerLayout="@layout/nav_header_main"/>

【问题讨论】:

  • 显示你的xml代码
  • 你拿过 NavigationDrawer 还是 NavigationView?
  • 您的 xml 有问题.. 发布您的 xml
  • DrawerLayout 应该是最顶层的父级。
  • try doing thisthis 希望对您有所帮助。

标签: android


【解决方案1】:

您需要将 DrawerLayout 作为父级..尝试这种方式它将对您有所帮助

<?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:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">

    <include
        layout="@layout/app_bar_main"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header_main"
        app:menu="@menu/activity_main_drawer" />

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

http://www.androidhive.info/2013/11/android-sliding-menu-using-navigation-drawer/

【讨论】:

    【解决方案2】:

    新的 App Compat 库支持此功能,您只需使用工具栏而不是操作栏,它比操作栏更具可定制性,并且比操作栏相对易于使用。

    将此添加到您的styles.xml

    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="dialogTheme">@style/Theme.Dialog</item>
    </style>
    <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Dark" />
    

    将此主题应用到您的应用程序manifest.xml

    <application
        ....
        ....
        android:theme="@style/AppTheme">
    

    现在像这样创建你的布局

    <?xml version="1.0" encoding="utf-8"?>
    <android.support.design.widget.CoordinatorLayout xmlns:tools="http://schemas.android.com/tools"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    
    <android.support.v4.widget.DrawerLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/drawer_layout"
        tools:openDrawer="start">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">
            <android.support.design.widget.AppBarLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/myAppBar"
                android:theme="@style/AppTheme.AppBarOverlay">
                <android.support.v7.widget.Toolbar
                    android:id="@+id/toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="?attr/actionBarSize"
                    android:background="?attr/colorPrimary"
                    app:popupTheme="@style/AppTheme.PopupOverlay"
                    app:title="Jewellery"/>
            </android.support.design.widget.AppBarLayout>
    
            <!--Your Layout Here-->
            <RelativeLayout 
                android:id="@+id/main_content"
                android:layout_width="match_parent"
                android:layout_height="match_parent">
                <ScrollView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_above="@+id/tabs"
                    android:id="@+id/scroll"
                    android:scrollbars="none">
                    <FrameLayout
                        android:id="@+id/container"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content">
    
                    </FrameLayout>
                </ScrollView>
            </RelativeLayout>
            <!-----Layout Ends-->
    
        </LinearLayout>
    
          <android.support.design.widget.NavigationView
              android:id="@+id/nav_view"
              android:layout_width="wrap_content"
              android:layout_height="match_parent"
              android:layout_gravity="start"
              android:fitsSystemWindows="true"
              app:headerLayout="@layout/nav_header"/>
       </android.support.v4.widget.DrawerLayout>
    </android.support.design.widget.CoordinatorLayout>
    

    现在在您的主要活动中

    Toolbar toolbar=(Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        if(getSupportActionBar()!=null){
            getSupportActionBar().setDisplayHomeAsUpEnabled(true);
            getSupportActionBar().setHomeButtonEnabled(true);
        }
    DrawerLayout mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.drawer_open, R.string.drawer_close);
    mDrawerLayout.addDrawerListener(mDrawerToggle);
    mDrawerToggle.syncState();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多