在Android的导航抽屉中具有imageview
我正在处理一个项目,其中有一个导航抽屉。在导航抽屉中,我想在listivew上方放置一个imageview。xml布局如下:在Android的导航抽屉中具有imageview,android,Android,我正在处理一个项目,其中有一个导航抽屉。在导航抽屉中,我想在listivew上方放置一个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.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" >
<!-- The main content view -->
<FrameLayout
android:id="@+id/frame_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<!-- The navigation drawer -->
<RelativeLayout
android:id="@+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:orientation="vertical"
android:clickable="true"
>
<ImageView
android:id="@+id/image_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/ic_logo" />
<ListView
android:id="@+id/slider_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#CC000000"
android:choiceMode="singleChoice"
android:divider="#808080"
android:layout_below="@id/image_view"
android:dividerHeight="0.5dp"
/>
</RelativeLayout>
</android.support.v4.widget.DrawerLayout>
问题是,在设备上运行时,imageview显示为挤压/压缩。为什么它显示为压缩?请帮助 要回答您的问题:
您将imageView的宽度设置为“匹配父对象”,高度设置为“包裹内容”,这将导致图像水平拉伸,除非它与设备的宽度相同-将宽度设置为“包裹内容”,并在必要时将图像居中
还有
相对布局没有方向,因此应删除线-
android:orientation="vertical"
在imageview中使用此属性:
android:adjustViewBounds="true"
另外,对可绘制文件使用src属性,而不是background属性:
android:src="@drawable/my_drawable"
发布一张图片,说明它在设备上的外观,以便我们能够更清楚地了解问题。您的
Imageview
高度为wrap\u content
,并且您没有指定在哪个设备上运行应用程序。这个问题是因为屏幕分辨率不同。在大设备中,图像将被压扁。因此,您需要对ImageView
应用一些固定高度。请指定图像视图的高度,或者使用压缩图像,并根据需要固定图像的高度和宽度desire@PiyushGupta.那么我可以用dp硬编码高度值吗?图标资源如下:hdpi:161x48px,mdpi:107x32px,xhdpi:214x63px,xxhdpi:321x95px,如何设置与all兼容的值,或者必须在布局文件夹中进行不同的布局?对于不同的屏幕分辨率,您只需将图像放在不同的可绘制的
文件夹中,不同的屏幕设备将使用不同的文件夹访问该文件夹。所以别担心。只需将固定高度应用于imageview。我正在将图像的宽度设置为与父项匹配,因为它将与导航抽屉的宽度匹配。