在android studio示例导航抽屉的导航抽屉中添加标题图像

时间:2021-08-17 06:20:15

i need to add header image like this Post :

我需要像这样添加标题图片:

can I add an image header in navigation drawer layout

我可以在导航抽屉布局中添加图像标题

but, im using android studio sample navigation drawer for doing this.

但是,即时通讯使用android studio示例导航抽屉来做这件事。

it is good or bad for design this ?

这对设计有好处还是坏处?

and the better way or Compact way for doing this ?

以及更好的方式或紧凑的方式来做到这一点?

any suggestion ?

有什么建议吗?

thanks.

2 个解决方案

#1


0  

Can I add an Image Header in Navigation Drawer Layout?

我可以在导航抽屉布局中添加图像标题吗?

Yes you can add with no problems.

是的,你可以添加没有问题。

If you use android studio navigation drawer or some thing else every thing are same. Some additional methods will be present and you need to check the methods required by you and delete other methods. You may also need to add few methods.

如果你使用android studio导航抽屉或其他一些东西是相同的。将出现一些其他方法,您需要检查您所需的方法并删除其他方法。您可能还需要添加一些方法。

As per the latest android, best way of designing navigation drawer is by using recycler view and by using material design.

根据最新的android,设计导航抽屉的最佳方法是使用回收站视图和使用材料设计。

There are lot of materials in google for doing this, one of the finest tutorials I prefer is in the link given below you can have a look:

谷歌有很多材料可以做到这一点,我喜欢的最好的教程之一是在下面给出的链接中你可以看看:

https://www.youtube.com/watch?v=zWpEh9k8i7Q&list=PLonJJ3BVjZW6CtAMbJz1XD8ELUs1KXaTD&index=6

Hope it helps.

希望能帮助到你。

#2


0  

In the menudrawer activity setcontentview(layout).Inside this layout

在menudrawer活动中setcontentview(布局)。在这个布局中

try to add an imageview.My sample xml is as folllows

尝试添加一个imageview.My示例xml如下

<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"

    android:layout_height="match_parent">

    <!-- As the main content view, the view below consumes the entire
         space available using match_parent in both dimensions. -->
    <FrameLayout
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:background="@android:color/transparent"
        android:layout_height="match_parent" />

    <!-- android:layout_gravity="start" tells DrawerLayout to treat
         this as a sliding drawer on the left side for left-to-right
         languages and on the right side for right-to-left languages.
         The drawer is given a fixed width in dp and extends the full height of
         the container. A solid background is used for contrast
         with the content view. -->

         <LinearLayout 
    android:layout_height="match_parent"
    android:layout_width="120dp"
       android:weightSum="7"
         android:layout_gravity="start"
       android:id="@+id/parentlayoutt"
        android:choiceMode="singleChoice"
       android:orientation="vertical"

     >

<ImageView
android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="3"
     android:id="@+id/headerimage"
  android:src="@drawable/yourimage"

/>
<RelativeLayout 
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
     android:id="@+id/parentmenuone"
     android:soundEffectsEnabled="true"
     android:descendantFocusability="blocksDescendants"

      android:background="@color/pure_white"
    >

        <ImageButton 
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:src="@drawable/birdwhite"
           android:background="@color/white"
           android:id="@+id/sidejive1"

         android:clickable="false"
            android:layout_centerInParent="true"          
            />


  <TextView 
       android:layout_height="wrap_content"
       android:layout_width="wrap_content"
      android:layout_centerHorizontal="true"
      android:layout_below="@+id/sidejive1"
       android:id="@+id/title1"
        android:clickable="false"
       android:textColor="@color/violetbg"

       android:text="@string/createmenu"

       />

</RelativeLayout>
<RelativeLayout 
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:descendantFocusability="blocksDescendants"
     android:id="@+id/parentmenutwo"
      android:background="@drawable/whitebox"
    >

        <ImageButton 
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:src="@drawable/profilewhite"
           android:background="@color/white"
           android:id="@+id/sidejive2"
            android:clickable="false"


            android:layout_centerInParent="true"          
            />


  <TextView 
       android:layout_height="wrap_content"
       android:layout_width="wrap_content"
      android:layout_centerHorizontal="true"
      android:layout_below="@+id/sidejive2"
       android:id="@+id/title2"
        android:clickable="false"
       android:textColor="@color/violetbg"

       android:text="@string/Accountmenu"

       />

</RelativeLayout>
<RelativeLayout 
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:descendantFocusability="blocksDescendants"
     android:id="@+id/parentmenuthree"
      android:background="@drawable/whitebox"
    >

        <ImageButton 
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:src="@drawable/homewhite"
           android:background="@color/white"
           android:id="@+id/sidejive3"
          android:clickable="false"

            android:layout_centerInParent="true"          
            />


  <TextView 
       android:layout_height="wrap_content"
       android:layout_width="wrap_content"
      android:layout_centerHorizontal="true"
      android:layout_below="@+id/sidejive3"
       android:id="@+id/title3"
       android:textColor="@color/violetbg"

       android:text="@string/Dashboardmenu"
      android:clickable="false"
       />

</RelativeLayout>
<RelativeLayout 
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
     android:id="@+id/parentmenufour"
     android:descendantFocusability="blocksDescendants"
      android:background="@drawable/whitebox"
    >

        <ImageButton 
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:src="@drawable/examplewhite"
           android:background="@color/white"
           android:id="@+id/sidejive4"
          android:clickable="false"

            android:layout_centerInParent="true"          
            />


  <TextView 
       android:layout_height="wrap_content"
       android:layout_width="wrap_content"
      android:layout_centerHorizontal="true"
      android:layout_below="@+id/sidejive4"
       android:id="@+id/title4"
       android:textColor="@color/violetbg"

       android:text="@string/Examplemenu"
      android:clickable="false"
       />

</RelativeLayout>
</LinearLayout>

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

#1


0  

Can I add an Image Header in Navigation Drawer Layout?

我可以在导航抽屉布局中添加图像标题吗?

Yes you can add with no problems.

是的,你可以添加没有问题。

If you use android studio navigation drawer or some thing else every thing are same. Some additional methods will be present and you need to check the methods required by you and delete other methods. You may also need to add few methods.

如果你使用android studio导航抽屉或其他一些东西是相同的。将出现一些其他方法,您需要检查您所需的方法并删除其他方法。您可能还需要添加一些方法。

As per the latest android, best way of designing navigation drawer is by using recycler view and by using material design.

根据最新的android,设计导航抽屉的最佳方法是使用回收站视图和使用材料设计。

There are lot of materials in google for doing this, one of the finest tutorials I prefer is in the link given below you can have a look:

谷歌有很多材料可以做到这一点,我喜欢的最好的教程之一是在下面给出的链接中你可以看看:

https://www.youtube.com/watch?v=zWpEh9k8i7Q&list=PLonJJ3BVjZW6CtAMbJz1XD8ELUs1KXaTD&index=6

Hope it helps.

希望能帮助到你。

#2


0  

In the menudrawer activity setcontentview(layout).Inside this layout

在menudrawer活动中setcontentview(布局)。在这个布局中

try to add an imageview.My sample xml is as folllows

尝试添加一个imageview.My示例xml如下

<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"

    android:layout_height="match_parent">

    <!-- As the main content view, the view below consumes the entire
         space available using match_parent in both dimensions. -->
    <FrameLayout
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:background="@android:color/transparent"
        android:layout_height="match_parent" />

    <!-- android:layout_gravity="start" tells DrawerLayout to treat
         this as a sliding drawer on the left side for left-to-right
         languages and on the right side for right-to-left languages.
         The drawer is given a fixed width in dp and extends the full height of
         the container. A solid background is used for contrast
         with the content view. -->

         <LinearLayout 
    android:layout_height="match_parent"
    android:layout_width="120dp"
       android:weightSum="7"
         android:layout_gravity="start"
       android:id="@+id/parentlayoutt"
        android:choiceMode="singleChoice"
       android:orientation="vertical"

     >

<ImageView
android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="3"
     android:id="@+id/headerimage"
  android:src="@drawable/yourimage"

/>
<RelativeLayout 
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
     android:id="@+id/parentmenuone"
     android:soundEffectsEnabled="true"
     android:descendantFocusability="blocksDescendants"

      android:background="@color/pure_white"
    >

        <ImageButton 
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:src="@drawable/birdwhite"
           android:background="@color/white"
           android:id="@+id/sidejive1"

         android:clickable="false"
            android:layout_centerInParent="true"          
            />


  <TextView 
       android:layout_height="wrap_content"
       android:layout_width="wrap_content"
      android:layout_centerHorizontal="true"
      android:layout_below="@+id/sidejive1"
       android:id="@+id/title1"
        android:clickable="false"
       android:textColor="@color/violetbg"

       android:text="@string/createmenu"

       />

</RelativeLayout>
<RelativeLayout 
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:descendantFocusability="blocksDescendants"
     android:id="@+id/parentmenutwo"
      android:background="@drawable/whitebox"
    >

        <ImageButton 
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:src="@drawable/profilewhite"
           android:background="@color/white"
           android:id="@+id/sidejive2"
            android:clickable="false"


            android:layout_centerInParent="true"          
            />


  <TextView 
       android:layout_height="wrap_content"
       android:layout_width="wrap_content"
      android:layout_centerHorizontal="true"
      android:layout_below="@+id/sidejive2"
       android:id="@+id/title2"
        android:clickable="false"
       android:textColor="@color/violetbg"

       android:text="@string/Accountmenu"

       />

</RelativeLayout>
<RelativeLayout 
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:descendantFocusability="blocksDescendants"
     android:id="@+id/parentmenuthree"
      android:background="@drawable/whitebox"
    >

        <ImageButton 
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:src="@drawable/homewhite"
           android:background="@color/white"
           android:id="@+id/sidejive3"
          android:clickable="false"

            android:layout_centerInParent="true"          
            />


  <TextView 
       android:layout_height="wrap_content"
       android:layout_width="wrap_content"
      android:layout_centerHorizontal="true"
      android:layout_below="@+id/sidejive3"
       android:id="@+id/title3"
       android:textColor="@color/violetbg"

       android:text="@string/Dashboardmenu"
      android:clickable="false"
       />

</RelativeLayout>
<RelativeLayout 
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
     android:id="@+id/parentmenufour"
     android:descendantFocusability="blocksDescendants"
      android:background="@drawable/whitebox"
    >

        <ImageButton 
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:src="@drawable/examplewhite"
           android:background="@color/white"
           android:id="@+id/sidejive4"
          android:clickable="false"

            android:layout_centerInParent="true"          
            />


  <TextView 
       android:layout_height="wrap_content"
       android:layout_width="wrap_content"
      android:layout_centerHorizontal="true"
      android:layout_below="@+id/sidejive4"
       android:id="@+id/title4"
       android:textColor="@color/violetbg"

       android:text="@string/Examplemenu"
      android:clickable="false"
       />

</RelativeLayout>
</LinearLayout>

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