ImageView 应该是全屏的,但高度错误
我正在开发一个简单的应用程序,它在屏幕的下半部分以纵向显示 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 中的 ImageView 是从单独的布局加载的:
<?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(全屏减去顶部栏),但包含的 ImageView 的尺寸为 480x240。
我已经为此奋斗了几个小时,摆弄 ImageSwitcher 和 ImageView 中的所有布局设置,但我无法让 ImageView 与其父级的 480x295 尺寸相匹配。任何帮助或见解表示赞赏。
I am working on a simple app that shows 4x3-aspect images in the lower half of the screen in portrait orientation, and filling the screen in landscape orientation. Portrait works and the 320x240 images (which are loaded over the net) are shown that size.
Rotate to landscape and I use a separate layout in res/layout-land which omits the upper half of the portrait layout and places the ImageSwitcher full screen. Some translucent controls overlay the image, so this uses a merge tag in the layout xml with the ImageSwitcher and a 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>
The ImageViews in the ImageSwitcher are loaded from a separate layout:
<?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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现了问题。我从 XML 布局中扩充了 ImageSwitcher 中的 ImageView,但这似乎不起作用。在代码中创建 ImageView 并为每个 ImageView 分配适当的 FrameLayout.LayoutParams 确实有效。
hierarchyviewer 在这里提供了很大的帮助 - 它强调了 ImageView 上的布局参数不是我所期望的。
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.