简体   繁体   English

导航抽屉与android中的curverd边缘

[英]Navigation drawer with curverd edge in android

I have done different Navigation Drawer types like Permanent,Persistent Mini variant,Temporary. 我做了不同的导航抽屉类型,如永久,持久迷你变种,临时。

All of them are rectangle in their outline shape like below. 所有这些都是如下所示的轮廓形状的矩形。

在此输入图像描述


Requirement : I want to create a Navigation Drawer with a curved edge(in its right side). 要求 :我想创建一个带有弯曲边缘的导航抽屉(在右侧)。

在此输入图像描述

Let's have a look on my nav. 我们来看看我的导航吧。 view 视图

 <android.support.design.widget.NavigationView
            android:background="#FFF"
            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"/>

It contains app:headerLayout and a app:menu . 它包含app:headerLayoutapp:menu If I can change the parent NavigationView edges those app:headerLayout and app:menu will be displayed inside it's parent boundaries. 如果我可以更改父NavigationView边缘,那么app:headerLayoutapp:menu将显示在其父边界内。 Am i right ? 我对吗 ?

Change of the android:background didn't work for me. 更改android:background对我不起作用。


What about adding dimen in dimens.xml is there any attribute that I can use? 怎么样加入dimendimens.xml是没有办法,我可以使用任何属性?

Is it possible to curve Navigation Drawer's edge (programmatically or using an image)? 是否可以曲线导航抽屉的边缘(以编程方式或使用图像)?

If yes any guidance will be highly appreciated. 如果是,任何指导都将受到高度赞赏。

Finally, I've decided to create library for this case: https://github.com/rom4ek/ArcNavigationView , feel free to explore and use it:) It's based on Florent Champigny's ArcLayout , with some adjustments, thanks to him. 最后,我决定为这个案例创建库: https//github.com/rom4ek/ArcNavigationView ,随时可以探索和使用它:)它基于Florent Champigny的ArcLayout ,有一些调整,多亏了他。

The advantage of this lib over suggested is that it was built on top of standard NavigationView from android design library, and you can use it as usual, just change the classname. 这个lib的优点是它建立 Android设计库的标准NavigationView 之上 ,你可以像往常一样使用它,只需更改类名即可。 Hopefully, will be published on jcenter soon. 希望很快就能在jcenter上发表。 Here are some screenshots: 以下是一些截图:

Thanks for the idea! 谢谢你的想法! :) :)

This Lib may helps you 这个Lib可以帮助你

https://github.com/mzule/FantasySlide https://github.com/mzule/FantasySlide

How to Use: XML 如何使用:XML

<com.github.mzule.fantasyslide.FantasyDrawerLayout   xmlns:app="http://schemas.android.com/apk/res-auto"
  android:id="@+id/drawerLayout"
  android:layout_width="match_parent"
  android:layout_height="match_parent">

<ImageView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scaleType="centerCrop"
    android:src="@drawable/fake" />// this image is part of home scren 

<com.github.mzule.fantasyslide.SideBar
    android:id="@+id/leftSideBar"
    android:layout_width="200dp"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:background="@color/colorPrimary"
    app:maxTranslationX="66dp"> // This attribute is for curve  

    <!--  SideBar  -->

</com.github.mzule.fantasyslide.SideBar>

JAVA: JAVA:

SideBar leftSideBar = (SideBar) findViewById(R.id.leftSideBar);
leftSideBar.setFantasyListener(new SimpleFantasyListener() {
  @Override
  public boolean onHover(@Nullable View view) {
    return false;
  }

  @Override
  public boolean onSelect(View view) {
     return false;
   }

  @Override
   public void onCancel() {
  }
});

According to me, to achieve this you will have to make your own custom class extending ViewGroup (or FrameLayout) like we have in DrawerLayout class. 据我所知,要实现这一点,你必须像在DrawerLayout类中一样创建自己的自定义类来扩展ViewGroup(或FrameLayout)。

EX: EX:

public class DrawerLayout extends ViewGroup implements DrawerLayoutImpl {
/*
..
*/
}

In your custom class, you can use Canvas and Paint to draw your preferred shape. 在自定义类中,可以使用Canvas和Paint绘制首选形状。 You can override the methods implement it in your way. 您可以覆盖以您的方式实现它的方法。

Then you can use it inside your Activity: 然后你可以在你的Activity中使用它:

MyDrawerLayout drawer = (MyDrawerLayout) findViewById(R.id.my_drawer_layout);

In your activity_file.xml : 在您的activity_file.xml中:

<com.yourpackage.MyDrawerLayout
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/my_drawer_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

<!-- .... -->

</com.yourpackage.MyDrawerLayout>

Use this from above library : 从上面的库中使用:

<?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"
    />
<com.rom4ek.arcnavigationview.ArcNavigationView
    android:id="@+id/nav_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:background="@android:color/white"
    android:fitsSystemWindows="true"
    app:menu="@menu/activity_main_drawer"
    app:itemBackground="@android:color/white"
    app:headerLayout="@layout/nav_header_main"
    app:arc_cropDirection="cropInside"
    app:arc_width="96dp"/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM