在导航抽屉添加标题图片在Android工作室样品抽屉式导航栏

在导航抽屉添加标题图片在Android工作室样品抽屉式导航栏

本文介绍了在导航抽屉添加标题图片在Android工作室样品抽屉式导航栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要添加标题图片类似这样的帖子:

i need to add header image like this Post :

添加图像标题

但是,采用了android工作室样本导航抽屉这样做IM。

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

这是好还是坏的设计呢?

it is good or bad for design this ?

和更好的方式或做这个紧凑的方式?

and the better way or Compact way for doing this ?

什么建议吗?

感谢。

推荐答案

在menudrawer活动的setContentView(布局).Inside此​​布局

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

尝试添加imageview.My样本XML是folllows

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

<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>

这篇关于在导航抽屉添加标题图片在Android工作室样品抽屉式导航栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 04:02