0

我正在开发一个简单的应用程序,该应用程序在屏幕的下半部分以纵向显示 4x3 纵横比的图像,并以横向填充屏幕。肖像作品和 320x240 图像(通过网络加载)显示为该尺寸。

旋转到横向,我在 res/layout-land 中使用了一个单独的布局,它省略了纵向布局的上半部分,并将 ImageSwitcher 全屏放置。一些半透明的控件覆盖了图像,因此这在布局 xml 中使用了带有 ImageSwitcher 和 RadioGroup 的合并标记:

<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android">

    <ImageSwitcher
        android:id="@+id/imageSwitcher"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_gravity="fill">
   </ImageSwitcher>

    <RadioGroup
        android:id="@+id/radioGroup"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|left"
        android:orientation="horizontal">
    ...
</merge>

ImageSwitcher 中的 ImageViews 是从单独的布局中加载的:

<?xml version="1.0" encoding="utf-8"?>
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_gravity="fill"
    android:scaleType="fitXY"
    android:adjustViewBounds="true"
    android:contentDescription="@null">
</ImageView>

For some reason the image views don't fill the screen however. Inspecting the view hierarchy with hierarchyviewer, I see that the ImageSwitcher has dimensions 480x295 (full screen minus the top bar), but the contained ImageViews have dimensions 480x240.

I've struggled with this for a couple of hours, fiddling with all the layout settings in the ImageSwitcher and the ImageViews but I can't get the ImageView to match the 480x295 dimension of its parent. Any help or insight appreciated.

4

1 回答 1

1

I found the problem. I was inflating the ImageViews in the ImageSwitcher from XML layouts, but this doesn't seem to work. Creating the ImageViews in code and assigning the appropriate FrameLayout.LayoutParams for each does work.

hierarchyviewer was a big help here - it highlighted that the layout params on the ImageViews were not what I was expecting.

于 2012-01-09T22:57:11.250 回答