ImageView的不填写父母 [英] ImageView won't fill parent

查看:99
本文介绍了ImageView的不填写父母的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的屏幕之一滚动型。我想右边缘有一个阴影。我决定做最简单的方法是使滚动型一个RelativeLayout的儿童,并有RelativeLayout的两个孩子 - 一个是LinearLayout中,将容纳屏幕的布局,第二是观影

I have a ScrollView on one of my screens. I want the right edge to have a shadow. I decided the easiest way to do this was to make the child of the ScrollView a RelativeLayout, and have two children of the RelativeLayout -- one being a LinearLayout that will house the layout of the screen, and the second View being the shadow.

像这样...

<ScrollView
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:scrollbars="none" >

            <RelativeLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content" >

                <LinearLayout
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical" >
                <!-- stuff -->
                </LinearLayout>

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    android:src="@drawable/shadow"
                    android:layout_alignParentRight="true"
                    />
            </RelativeLayout>
        </ScrollView>

不幸的是,这完全不是那么回事。 ImageView的迫使其尺寸为图像文件的大小。它不会垂直拉伸成为RelativeLayout的高度。我也试着match_parent无济于事。该图像是一个9补丁。

Unfortunately, this doesn't quite work. The ImageView is forcing its dimensions to be the size of the image file. It will not stretch vertically to be the height of the RelativeLayout. I've also tried "match_parent" to no avail. The image is a 9-patch.

想法?

推荐答案

应用绘制的内容作为的ImageView 的来源有点用它进行所需的内在要求查看到竭尽所能,以适应内容,而无需修改内容本身非常多。通常,这是你想出来的行为的ImageView

Applying drawable content as the source of an ImageView somewhat carries with it an inherent requirement that you want the view to do what it can to accomodate the content without modifying the content itself very much. Typically, this is the behavior you would want out of an ImageView.

你真正想要的是可以通过设置可绘制的内容作为背景的视图,为你并不真的需要获得行为ImageView的可言。背景是设计简单的拉伸,填充等的任何尺寸的观点。此外,由于使用的是 RelativeLayout的你可以告诉视图相匹配的约束,你是通过添加 ID 和一些额外的 layout_align 参数。

What you really want is the behavior you get by setting drawable content as the background of a view, for which you don't really need ImageView at all. A background is designed to simply stretch, fill, etc. to whatever size the view is. Also, since you are using RelativeLayout you can tell the view to match the bound of the view you are shadowing by adding an id and some extra layout_alignparameters.

        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" >

            <LinearLayout
                android:id="@+id/content_layout"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical" >
            <!-- stuff -->
            </LinearLayout>

            <View
                android:layout_width="11dp"
                android:layout_height="fill_parent"
                android:layout_alignParentRight="true"
                android:layout_alignTop="@id/content_layout"
                android:layout_alignBottom="@id/content_layout"
                android:background="@drawable/shadow"
                />
        </RelativeLayout>

这篇关于ImageView的不填写父母的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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