在ImageView中wrap_content失效

在ImageView中wrap_content失效

代码如下

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

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="点餐START!!"
        android:textColor="#000fff"
        android:textSize="40sp"
        android:background="#fff000"/>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="姓名"/>
        <EditText
            android:layout_width="100dp"
            android:layout_height="wrap_content"
            android:hint="姓名" />
    </LinearLayout>


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="性别"/>
        <RadioGroup
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal">
            <RadioButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="男"/>
            <RadioButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="女"/>
        </RadioGroup>
    </LinearLayout>


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="喜好"/>
        <CheckBox
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="辣"/>
        <CheckBox
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="海鲜"/>
        <CheckBox
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="酸"/>
    </LinearLayout>


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="预算"/>
        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:text="0元"
            android:layout_weight="1"
            android:textAlignment="textEnd"/>
        <SeekBar
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:max="100"
            android:min="0"
            android:layout_weight="4"/>
        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:text="100元"
            android:layout_weight="2"/>
    </LinearLayout>
    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="寻找菜品"
        android:textSize="25sp"/>

    <ImageView
        android:layout_width="180dp"
        android:layout_height="wrap_content"
        android:src="@drawable/hongshaorou" />
    <ToggleButton
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textOn="寻找"
        android:textOff="下一个"/>
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="ssss"/>
</LinearLayout>

就是ImageView那里的宽高显示不对,效果如下

http://img1.sycdn.imooc.com//climg/5a9e052f0001295a02930491.jpg

蓝色边框的即为ImageView

然后那张图片如下

http://img1.sycdn.imooc.com//climg/5a9e05750001e85107000450.jpg

谢谢了,Orz

正在回答 回答被采纳积分+1

登陆购买课程后可参与讨论,去登陆

1回答
好帮手慕雪 2018-03-06 11:24:10

ImageView的android:layout_height修改完之后,是不是没有保存呢?保存后再试试。另外:XML视图预览与运行后的实际效果还是稍有区别的,运行看效果。祝:学习愉快

  • 提问者 慕沐1536820 #1
    大佬好,首先,我保存了,其次,运行起来也是这样
    2018-03-06 13:51:26
  • 好帮手慕雪 回复 提问者 慕沐1536820 #2
    ImageView设置长度高度为wrap_content时,高度根据图片比例自适应 了,就可能会出现上述情况,这时给ImageView添加android:adjustViewBounds="true"就是你想要的效果了。
    2018-03-06 14:30:22
  • 提问者 慕沐1536820 回复 好帮手慕雪 #3
    你好,谢谢,但是能请你解释为啥么,我不是特别明白,上网百度了后他们说需要与maxWidth、MaxHeight一起使用,否则单独使用没有效果,我这样用为啥又可以生效,而且我为什么需要加这一条语句,谢谢啦
    2018-03-13 17:14:10
问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
意见反馈 帮助中心 APP下载
官方微信

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师