【问题标题】:Android cannot align ImageView to top of activityAndroid 无法将 ImageView 对齐到活动顶部
【发布时间】:2011-07-06 17:58:47
【问题描述】:

由于某种原因,我很难将 ImageView 与我的 Android 应用程序中的活动顶部对齐。例如:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

    <ImageView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:scaleType="fitStart"
        android:src="@drawable/myImage" />

    <ListView android:id="@android:id/list"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />
</LinearLayout>

我能够使用“fitStart”让 ImageView 与 Activity 的顶部对齐,但如果没有它,那么 imageView 就不会一直位于顶部。现在 ImageView 在顶部,ListView 不在它的正下方。相反,它是屏幕向下的四分之一。这发生在我的所有活动中,即使是没有 ListView 的活动。

作为旁注,我确实从 AndroidManifest 中的活动中删除了系统标题栏。但是,即使我重新添加它们,问题仍然存在。

有什么想法吗?

【问题讨论】:

    标签: android listview android-activity imageview


    【解决方案1】:

    使用RelativeLayout的修复

    【讨论】:

      【解决方案2】:

      您好,问题是您使用android:layout_gravity="center_horizontal" 作为图像视图,它将视图与父布局的中心对齐...

      也可以看看this

      希望这能解决你的问题...

      【讨论】:

      • 嗯,即使我删除了 "android:layout_gravity="center_horizo​​ntal" 我仍然面临 ImageView 和 ListView 无法与活动顶部对齐的问题...
      【解决方案3】:

      可能是因为您的图片有透明边框?这就是我的意思:

      【讨论】:

      • 不幸的是,情况并非如此,我确信没有透明边框。好主意,不过!
      • 您能否将您的图片上传到您的问题中?我想在我的布局中使用它...
      • 好的,我在您的布局中使用了纯色图像,在我的情况下,图像与顶部完美对齐。
      【解决方案4】:

      我使用的图像似乎太大了,缩放后出现了问题。一旦我使用了较小的图像,一切都与顶部完美对齐。谢谢!

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-12-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多