简体   繁体   中英

Can't get imageview to sit flush with the top of the screen

I'm trying to place an image view at the top of the screen, but it has some type of margin above and below it. So I tried adjustViewBounds = true, and it worked but then it wouldn't reach the sides of the screen. I just want it to be flush with the top of the screen, and reach the sides. Any suggestions?

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="match_parent"
tools:context="${packageName}.${activityClass}"
android:orientation="vertical" >

<ImageView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:src="@drawable/title_bar"/>

<ScrollView
    android:id="@+id/scrollView1"
    android:layout_width="fill_parent"
    android:layout_height="200dp" >

    <LinearLayout
        android:id="@+id/goals"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        android:orientation="vertical" >
    </LinearLayout>
</ScrollView>

<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="match_parent"
    android:background="@android:color/black" >
</RelativeLayout>

If it is just colored title bar - then it is make sense to use just View for example and set background property to needed color. If You have custom image for that and can not adjust it with default ImageView properties - then You can make 9Patch from your image and use it as a background also (in 9patch you decide by yourself how to scratch image and where to place content). You can find 9patch tool in android SDK. More info about 9patch: http://developer.android.com/reference/android/graphics/NinePatch.html

I had this same problem. What I ended up doing was using a negative margin on the top of the ImageView like so:

android:layout_marginTop="-4dp"

You may have to play around to find the optimal number of dp for you. Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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