在Android中的导航抽屉内部有一个imageview

时间:2015-01-24 04:35:46

标签: android

我正在进行一个有导航抽屉的项目。在导航抽屉中,我想将一个imageview放在一个listivew上面.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" >

    <!-- 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>

问题是图像视图在设备上运行时会出现压扁/压缩。为什么它看起来像是压缩的?请帮助!!

2 个答案:

答案 0 :(得分:0)

回答你的问题: 你将imageView宽度设置为&#34; match_parent&#34;和高度设置为&#34; wrap_content&#34;这将导致图像水平拉伸,除非它与设备的宽度相同 - 将宽度设置为&#34; wrap_content&#34;并在必要时使图像居中。

...也

相对布局没有方向,因此您应该删除该行 -

android:orientation="vertical"

答案 1 :(得分:0)

在imageview中使用此属性:

android:adjustViewBounds="true"

另外,使用src属性作为drawable,而不是background属性:

android:src="@drawable/my_drawable"