Android 其中,在导航抽屉顶部添加ImageView
我按照CodePath中的教程在android中创建了导航抽屉: 我想实现的是将图像视图添加到列表视图的上方,我尝试了不同的解决方案,但都不起作用 这是activity_main.xmlAndroid 其中,在导航抽屉顶部添加ImageView,android,xml,android-layout,android-fragments,navigation-drawer,Android,Xml,Android Layout,Android Fragments,Navigation Drawer,我按照CodePath中的教程在android中创建了导航抽屉: 我想实现的是将图像视图添加到列表视图的上方,我尝试了不同的解决方案,但都不起作用 这是activity_main.xml <my.custom.package.path.FragmentNavigationDrawer xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/drawer_layout"
<my.custom.package.path.FragmentNavigationDrawer
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:orientation="vertical">
<!-- The ActionBar -->
<include
layout="@layout/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<!-- The main content view -->
<FrameLayout
android:id="@+id/flContent"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<!-- The navigation drawer -->
<ListView
android:id="@+id/lvDrawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:paddingTop="24dp"
android:divider="@android:color/darker_gray"
android:dividerHeight="0dp"
android:background="@android:color/background_light" />
</my.custom.package.path.FragmentNavigationDrawer>
这是drawer_nav_item.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="48dp">
<ImageView
android:id="@+id/ivIcon"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_alignParentLeft="true"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp"
android:layout_centerVertical="true" />
<TextView
android:id="@+id/tvTitle"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_toRightOf="@id/ivIcon"
android:minHeight="?android:attr/listPreferredItemHeightSmall"
android:textAppearance="?android:attr/textAppearanceListItemSmall"
android:gravity="center_vertical"
android:paddingRight="40dp"/>
</RelativeLayout>
最终的结果是:
我想要实现的是:
但只有背景图像在顶部
有人能帮我吗
最好的
Brus如果您对材质设计样式导航抽屉感兴趣,请查看此答案:如果您对材质设计样式导航抽屉感兴趣,请查看此答案:如果您对材质设计样式导航抽屉感兴趣,看看这个答案:如果你对材料设计风格的导航抽屉感兴趣,看看这个答案:
将ImageView置于LinearLayout中的Listview上方
将ImageView置于LinearLayout中的Listview上方
将ImageView置于LinearLayout中的Listview上方
将ImageView置于LinearLayout中Listview的上方如果您想要列表上方的静态图像,请使用@VjLxmi else的应答创建自定义布局并将其添加为列表视图的标题视图。如果您想要列表上方的静态图像,请使用@VjLxmi else的应答创建自定义布局并将其添加为列表视图的标题视图。如果您想要列表上方的静态图像,请使用应答@VjLxmi else的答案创建自定义布局并将作为标题视图添加到listview。如果您想要列表上方的静态图像,请使用@VjLxmi else的答案创建自定义布局并将作为标题视图添加到listview。
<my.custom.package.path.FragmentNavigationDrawer
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:orientation="vertical">
<!-- The ActionBar -->
<include
layout="@layout/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<!-- The main content view -->
<FrameLayout
android:id="@+id/flContent"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<!-- The navigation drawer -->
<LinearLayout
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:orientation="vertical">
<!--Place your ImageView here-->
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher"/>
<ListView
android:id="@+id/lvDrawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:choiceMode="singleChoice"
android:paddingTop="24dp"
android:divider="@android:color/darker_gray"
android:dividerHeight="0dp"
android:background="@android:color/background_light" />
</LinearLayout>
</my.custom.package.path.FragmentNavigationDrawer>