繁体   English   中英

Android 无法将 ImageView 与活动顶部对齐

[英]Android cannot align ImageView to top of activity

出于某种原因,我很难将 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 与活动的顶部对齐,但如果没有它,那么 imageView 就不会一直处于顶部。 现在 ImageView 位于顶部,ListView 不在其正下方。 相反,它是屏幕向下的四分之一。 这发生在我的所有活动中,即使是没有 ListView 的活动。

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

有任何想法吗?

通过使用 RelativeLayout 修复

嗨,问题是你 r 使用android:layout_gravity="center_horizontal"用于 imageview 的父布局的中心...

也看看这个

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

也许那是因为您的图像具有透明边框? 这就是我的意思:

在此处输入图像描述

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM