Android 无法将 ImageView 与 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 中的活动中删除了系统标题栏。但是,即使我将它们重新添加进去,问题仍然存在。
有什么想法吗?
For some reason, I'm having difficulty aligning ImageView's to the top of the activities in my Android applications. For example:
<?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>
I was able to get the ImageView to align to the top of the activity with "fitStart", but without that then the imageView wouldn't be all the way at the top. Now that the ImageView is on top, the ListView isn't directly below it. Instead, it is a quarter of the screen down. This is happening on all of my activities, even ones without ListView's.
As a side note, I did remove the system title bars from my activities in AndroidManifest. However, even when I add them back in, the problem is still occurring.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
使用RelativeLayout 修复
Fixed by using RelativeLayout's
您好,问题是您对 imageview 使用
android:layout_gravity="center_horizontal"
,这会将视图与父布局的中心对齐...还可以查看 这个
希望这能解决您的问题...
hi the problem is that u r using
android:layout_gravity="center_horizontal"
for the imageview which will align the view to the center of the parent layout...also have look at this
Hope this solves your problem...
也许这是因为你的图像有透明边框?这就是我的意思:
Maybe that's because your image has transparent borders? Here is what I mean:
看来我使用的图像太大了,缩放后出现了问题。一旦我使用了较小的图像,所有内容都完美地与顶部对齐。谢谢!
It seems that the image that I was using was too large, and after it scaled the problem was occurring. Once I used a smaller image, everything aligned perfectly to the top. Thanks!