开发者

Android cannot align ImageView to top of activity

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?


Fixed by using RelativeLayout's


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:

Android cannot align ImageView to top of activity


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!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜