简体   繁体   English

无法使imageview与屏幕顶部齐平

[英]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. 所以我尝试了AdjustViewBounds = true,它可以正常工作,但随后无法到达屏幕两侧。 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. 如果标题栏仅是彩色的,则仅使用View并将背景属性设置为所需的颜色是有意义的。 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). 如果您具有自定义图像,并且无法使用默认的ImageView属性进行调整-那么您可以从图像中制作9Patch并将其用作背景(在9patch中,您可以自行决定如何抓取图像以及在哪里放置内容)。 You can find 9patch tool in android SDK. 您可以在android SDK中找到9patch工具。 More info about 9patch: http://developer.android.com/reference/android/graphics/NinePatch.html 有关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: 我最终要做的是在ImageView的顶部使用负边距,如下所示:

android:layout_marginTop="-4dp"

You may have to play around to find the optimal number of dp for you. 您可能需要四处寻找最佳的dp数量。 Hope this helps. 希望这可以帮助。

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

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