【问题标题】:ImageView should be full screen but has wrong heightImageView 应该是全屏但高度错误
【发布时间】:2012-01-10 06:57:11
【问题描述】:

我正在开发一个简单的应用程序,该应用程序在屏幕的下半部分以纵向显示 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>

由于某种原因,图像视图并没有填满屏幕。使用 hierarchyviewer 检查视图层次结构,我看到 ImageSwitcher 的尺寸为 480x295(全屏减去顶部栏),但包含的 ImageViews 尺寸为 480x240。

我已经为此苦苦挣扎了几个小时,摆弄了 ImageSwitcher 和 ImageViews 中的所有布局设置,但我无法让 ImageView 与其父级的 480x295 尺寸相匹配。任何帮助或见解表示赞赏。

【问题讨论】:

    标签: android layout imageview imageswitcher


    【解决方案1】:

    我发现了问题。我从 XML 布局中对 ImageSwitcher 中的 ImageViews 进行膨胀,但这似乎不起作用。在代码中创建 ImageViews 并为每个分配适当的 FrameLayout.LayoutParams 确实有效。

    hierarchyviewer 在这里起到了很大的帮助 - 它强调了 ImageViews 上的布局参数不是我所期望的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-02
      • 2011-10-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多