首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ImageView scaleType不工作

ImageView scaleType不工作
EN

Stack Overflow用户
提问于 2015-03-11 16:05:36
回答 1查看 7K关注 0票数 4

我有一个ImageView,其中包含了一点"?“作为图像。这个图像被拉伸了,看起来很难看。因此,我尝试将ImageViews.caleType-属性设置为fitCenter,但没有任何效果。我也尝试了所有其他的scaleTypes,但是没有影响我的布局。由于用户稍后可以在ImageView中上传任何大小的图片,所以我希望我的ImageView始终适合它的中心位置。以下是我的xml文件:

代码语言:javascript
复制
<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:orientation="vertical">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal">

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/imageButton"
            android:background="@android:drawable/ic_menu_save"
            android:layout_alignParentTop="true"
            android:layout_alignParentRight="true"
            android:layout_alignParentEnd="true" />

        <EditText
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/editText"
            android:hint="name of question"
            android:layout_alignParentTop="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true" />
    </RelativeLayout>

    <ImageView
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:id="@+id/imageViewQuestion"
        android:layout_gravity="center_horizontal"
        android:background="@android:drawable/ic_menu_help"
        android:layout_weight="1"
        android:cropToPadding="false"
        android:onClick="clickQuestion"
        android:scaleType="centerCrop" />

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/textViewQuestion"
        android:layout_gravity="center_horizontal"
        android:layout_weight="0.11"
        android:textAlignment="center"
        android:hint="Question"
        android:onClick="clickQuestion"
        android:gravity="center" />

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.60">

        <Button
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:text="1"
            android:id="@+id/button1"
            android:layout_weight="2"
            android:onClick="clickButtonEdit" />

        <Button
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:text="2"
            android:id="@+id/button2"
            android:layout_weight="2"
            android:onClick="clickButtonEdit" />

        <Button
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:text="3"
            android:id="@+id/button3"
            android:layout_weight="2"
            android:onClick="clickButtonEdit" />

        <Button
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:text="4"
            android:id="@+id/button4"
            android:layout_weight="2"
            android:onClick="clickButtonEdit" />
    </LinearLayout>

</LinearLayout>

有人看到我的错误了吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-03-11 16:09:58

尝试使用src而不是background

替换

代码语言:javascript
复制
android:background="@android:drawable/ic_menu_help"

通过

代码语言:javascript
复制
android:src="@android:drawable/ic_menu_help"
票数 37
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28991639

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档