【发布时间】:2015-03-31 04:46:44
【问题描述】:
我需要像这样添加标题图片:
can I add an image header in navigation drawer layout
但是,我使用 android studio 示例导航抽屉来执行此操作。
这样设计是好是坏?
还有更好的方法或紧凑的方法吗?
有什么建议吗?
谢谢。
【问题讨论】:
标签: android android-listview navigation-drawer
我需要像这样添加标题图片:
can I add an image header in navigation drawer layout
但是,我使用 android studio 示例导航抽屉来执行此操作。
这样设计是好是坏?
还有更好的方法或紧凑的方法吗?
有什么建议吗?
谢谢。
【问题讨论】:
标签: android android-listview navigation-drawer
我可以在导航抽屉布局中添加图像标题吗?
是的,您可以毫无问题地添加。
如果你使用 android studio 导航抽屉或其他东西,一切都是一样的。一些额外的方法会出现,您需要检查您需要的方法并删除其他方法。您可能还需要添加一些方法。
根据最新的 android,设计导航抽屉的最佳方法是使用回收器视图和使用材料设计。
谷歌有很多材料可以做到这一点,我更喜欢的最好的教程之一是在下面给出的链接中,你可以看看:
https://www.youtube.com/watch?v=zWpEh9k8i7Q&list=PLonJJ3BVjZW6CtAMbJz1XD8ELUs1KXaTD&index=6
希望对你有帮助。
【讨论】:
在 menudrawer 活动 setcontentview(layout).Inside 这个布局中
尝试添加一个 imageview。我的示例 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>
【讨论】: