gpt4 book ai didi

android - 抽屉导航顶部的图像

转载 作者:行者123 更新时间:2023-11-29 00:24:13 25 4
gpt4 key购买 nike

如何将图片放在抽屉导航顶部,例如 Google Play 商店或 Google+ 上的左侧边栏?

实际上我有自己的抽屉导航适配器,它为 ListView 的每个元素放置了一个图标,这是当前的 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" >

<FrameLayout
android:id="@+id/frame_content"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</FrameLayout>

<ListView
android:id="@+id/left_menu"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@color/menuBackground"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp" />

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

我想我必须在这个 XML 中添加 ImageView,但我不确定这是否是正确的方法。

最佳答案

我今天才知道如何实现这个(如果你还没有解决这个问题的话)。

我花了几个小时提出正确的问题

我觉得你看起来像这样

Image on top of the listview

如果是这样,您需要创建一个 xml 文件作为 header 并添加到 ListView 的顶部。

所以只要创建一个header.xml

header.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >

<ImageView
android:id="@+id/img_first"
android:layout_width="fill_parent"
android:layout_height="200dp"
android:scaleType="fitXY"
android:src="@drawable/hatsune" />

<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Text Name"
android:background="#88f3f3f3"
android:textAppearance="?android:attr/textAppearanceLarge" />

<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="20dp"
android:background="#88f3f3f3"
android:text="Text Point"
android:textAppearance="?android:attr/textAppearanceLarge" />

</RelativeLayout>

回到你的 Activity 让我们说 Activity.java

//Header of the listview, go to header.xml to customize
View header = getLayoutInflater().inflate(R.layout.header, null);

//addHeaderView is to add custom content into first row
yourListView.addHeaderView(header);
yourListView.setAdapter(yourAdapter);

关于android - 抽屉导航顶部的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20922352/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com