Android:导航抽屉标题图像 [英] Android: Navigation Drawer Header Image

查看:62
本文介绍了Android:导航抽屉标题图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试为我的所有活动创建一个导航抽屉.我使用Android Studio并生成导航抽屉活动.我的其他活动在其中进行了扩展,以获取导航抽屉.我插入了具有Android Studio功能的Pictue,现在在"mipmap"文件夹中存在hdpi和xhdpi....

I try to create a Navigation Drawer for all my Activities. I use Android Studio and generate a Navigation Drawer Activity. My other Activities extends in it to get the Navigation Drawer. I insert a Pictue with the Android Studio Feature and now exist the hdpi and xhdpi... in the "mipmap" Folder.

我将导航标题布局背景更改为插入的图像:

I change in the Navigation Header Layout Background to my inserted Image:

android:background="@mipmap/ic_lmg_bck"

nav_header_nd.xml

nav_header_nd.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="@dimen/nav_header_height"
    android:background="@mipmap/ic_lmg_bck"
    android:gravity="bottom"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:theme="@style/ThemeOverlay.AppCompat.Dark">

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingTop="@dimen/nav_header_vertical_spacing"
        app:srcCompat="@drawable/ic_launcher" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="@dimen/nav_header_vertical_spacing"
        android:text="Nutzername"
        android:textAppearance="@style/TextAppearance.AppCompat.Body1" />

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Nutzernameemail" />

</LinearLayout>

除了图像模糊而且很小以外,所有作品都可以使用:

All works but the Image is blurred and to small:

原始图片:

如何调整图像大小?

推荐答案

要添加背景,您只需要将图片复制/粘贴到drawable文件夹中(不要使用添加新的图像资产"添加图像)

To add the background, you need to only copy/paste your picture to the drawable folder (Don´t add the Image with "add new Image Asset").

此后,您将转到:nav_header_nd.xml

After this you go to your: nav_header_nd.xml

并将背景更改为:

android:background="@drawable/mypicture"

这篇关于Android:导航抽屉标题图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆