不是的LinearLayout包装内容 [英] LinearLayout not wrapping content

查看:129
本文介绍了不是的LinearLayout包装内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用的LinearLayout来堆叠水平4图像和它运作良好,除了高度。似乎的LinearLayout未正确包裹它的内容。如果我没有图像规模类型设置为fitStart,他们将在里面的LinearLayout为中心。

下面是我下面的布局:

 <的LinearLayout
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_gravity =顶
    机器人:方向=横向
    机器人:weightSum =4
    机器人:layout_marginLeft =40dp
    机器人:layout_marginRight =40dp>    < ImageView的
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:ID =@ + ID / ImageView的
        机器人:SRC =@绘制/头1
        机器人:layout_weight =1
        机器人:scaleType =fitStart/>    < ImageView的
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =WRAP_CONTENT
        机器人:ID =@ + ID / imageView2
        机器人:layout_gravity =center_vertical
        机器人:SRC =@绘制/ HEADER2
        机器人:layout_weight =1
        机器人:scaleType =fitStart/>    < ImageView的
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =WRAP_CONTENT
        机器人:ID =@ + ID / imageView3
        机器人:layout_gravity =center_vertical
        机器人:SRC =@绘制/ header3color
        机器人:layout_weight =1
        机器人:scaleType =fitStart/>    < ImageView的
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =WRAP_CONTENT
        机器人:ID =@ + ID / imageView4
        机器人:SRC =@绘制/ header4
        机器人:layout_weight =1
        机器人:scaleType =fitStart/>
< / LinearLayout中>


解决方案

尝试 adjustViewBounds 属性设置为真正对于那些图像。
<一href=\"http://developer.android.com/reference/android/widget/ImageView.html#attr_android:adjustViewBounds\" rel=\"nofollow\">http://developer.android.com/reference/android/widget/ImageView.html#attr_android:adjustViewBounds

这应该带你有额外的空间的关怀和的LinearLayout应 WRAP_CONTENT 正常。

I used LinearLayout to stack 4 images horizontally and it works well except for the height. It seems that the linearlayout is not properly wrapping its content. If I don't set the images' scale type to fitStart, they will be centered inside the linearlayout.

Here is my layout below:

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="top"
    android:orientation="horizontal"
    android:weightSum="4"
    android:layout_marginLeft="40dp"
    android:layout_marginRight="40dp">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/imageView"
        android:src="@drawable/header1"
        android:layout_weight="1"
        android:scaleType="fitStart" />

    <ImageView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/imageView2"
        android:layout_gravity="center_vertical"
        android:src="@drawable/header2"
        android:layout_weight="1"
        android:scaleType="fitStart" />

    <ImageView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/imageView3"
        android:layout_gravity="center_vertical"
        android:src="@drawable/header3color"
        android:layout_weight="1"
        android:scaleType="fitStart" />

    <ImageView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/imageView4"
        android:src="@drawable/header4"
        android:layout_weight="1"
        android:scaleType="fitStart" />
</LinearLayout>

解决方案

Try setting the adjustViewBounds attribute to true for those images. http://developer.android.com/reference/android/widget/ImageView.html#attr_android:adjustViewBounds

That should take care of that extra space you have and the LinearLayout should wrap_content correctly.

这篇关于不是的LinearLayout包装内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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