Linearlayout 中的背景图像

发布于 2024-11-07 09:38:09 字数 10845 浏览 0 评论 0原文

我正在为我正在使用的线性布局的背景设置图像。我遇到的问题是标题栏下方的白色边框。如果我将背景设置为某种颜色,则不会出现白色边框。有谁知道可能是什么原因造成的。

背景图像问题

我正在动态加载一些内容,但这里是 xml

<?xml version="1.0" encoding="utf-8"?>
<android.gesture.GestureOverlayView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/gestures"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gestureStrokeType="single"
    android:eventsInterceptionEnabled="true"
    android:orientation="vertical"
    android:uncertainGestureColor="#00000000"
    android:gestureColor="#00000000">
<ScrollView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">


<LinearLayout android:id="@+id/LinearLayout01"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:padding="20dip"
    android:background="@drawable/background">
<!--     android:background="@drawable/background"> -->


    <TextView 
        android:id="@+id/item_text"
        android:layout_height="wrap_content"
        android:textSize="16sp"
        android:layout_gravity="center"
        android:text="@string/item_text"
        android:textColor="#fffafa"
        android:layout_width="wrap_content"
        android:textStyle="bold"
        android:paddingBottom="10dip"/>

    <LinearLayout
        android:id="@+id/photoLayout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:paddingBottom="20dip"/>     

     <LinearLayout android:id="@+id/LinearLayoutDynamic"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:padding="10dp"
        android:orientation="vertical"
        android:background="@drawable/my_border">

     </LinearLayout>

     <TextView 
        android:id="@+id/item_text1"
        android:layout_height="wrap_content"
        android:paddingTop="20dip"
        android:paddingBottom="10dip"
        android:textSize="16sp"
        android:layout_gravity="center"
        android:text="Besonderheiten"
        android:textColor="#fffafa"
        android:layout_width="wrap_content"
        android:textStyle="bold"/>

    <LinearLayout android:id="@+id/RelativeLayout01"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"

        android:orientation="vertical"
        android:background="@drawable/my_border">

        <RelativeLayout
            android:id="@+id/LinearLayout"
            android:layout_height="fill_parent"
            android:layout_width="fill_parent"
            android:orientation="horizontal">   


            <TextView 
                style="@style/CodeFont"
               android:id="@+id/item_wasteDisposal"
               android:text="@string/item_wasteDisposal"
               android:textSize="14sp"
               android:singleLine="true"/>  

            <ImageView 
                android:layout_height="wrap_content"  
                android:layout_width="wrap_content" 
                android:id="@+id/wasteDisposalImage"
                android:layout_toRightOf="@id/item_wasteDisposal"
                android:padding="5dp"/>

            <View
                android:layout_height="1dip"
                android:background="#FF909090"
                android:layout_below="@id/wasteDisposalImage"
                android:layout_width="fill_parent"/>


            <ImageView
                android:layout_height="wrap_content" 
                android:layout_width="wrap_content" 
                android:id="@+id/internetImage"
                android:layout_below="@id/wasteDisposalImage"
                android:layout_alignLeft="@id/wasteDisposalImage"
                android:padding="5dp"/>

            <TextView 
                style="@style/CodeFont"
                android:id="@+id/item_internet"
                android:text="@string/item_internet"
                android:textSize="14sp"
                android:layout_toLeftOf="@id/internetImage"
                android:layout_below="@id/wasteDisposalImage"/>

            <View
                android:layout_height="1dip"
                android:background="#FF909090"
                android:layout_below="@id/internetImage"
                android:layout_width="fill_parent"/>


            <ImageView 
                android:layout_height="wrap_content" 
                android:layout_width="wrap_content"
                android:id="@+id/overnightStayImage"
                android:layout_below="@id/internetImage"
                android:layout_alignLeft="@id/internetImage"
                android:padding="5dp"/>

            <TextView 
                style="@style/CodeFont"
                android:id="@+id/item_overnightStay"
                android:text="@string/item_overnightStay"
                android:textSize="14sp"
                android:layout_toLeftOf="@id/overnightStayImage"
                android:layout_below="@id/internetImage"/>  

                            <View
                android:layout_height="1dip"
                android:background="#FF909090"
                android:layout_below="@id/overnightStayImage"
                android:layout_width="fill_parent"/>

            <ImageView 
                android:layout_height="wrap_content" 
                android:layout_width="wrap_content" 
                android:id="@+id/toiletImage"
                android:layout_below="@id/overnightStayImage"
                android:layout_alignLeft="@id/overnightStayImage"
                android:padding="5dp"/>

            <TextView 
                style="@style/CodeFont"
                android:id="@+id/item_toilet"
                android:text="@string/item_toilet"
                android:textSize="14sp"
                android:layout_toLeftOf="@id/toiletImage"
                android:layout_below="@id/overnightStayImage"/>

                            <View
                android:layout_height="1dip"
                android:background="#FF909090"
                android:layout_below="@id/toiletImage"
                android:layout_width="fill_parent"/>

            <ImageView 
                android:layout_height="wrap_content"
                android:layout_width="wrap_content" 
                android:id="@+id/electricityImage"
                android:layout_below="@id/toiletImage"
                android:layout_alignLeft="@id/toiletImage"
                android:padding="5dp"/>

            <TextView 
                style="@style/CodeFont"
                android:id="@+id/item_electricity"
                android:text="@string/item_electricity"
                android:textSize="14sp"
                android:layout_toLeftOf="@id/electricityImage"
                android:layout_below="@id/toiletImage"/>                

                        <View
                android:layout_height="1dip"
                android:background="#FF909090"
                android:layout_below="@id/electricityImage"
                android:layout_width="fill_parent"/>

            <ImageView 
                android:layout_height="wrap_content" 
                android:layout_width="wrap_content" 
                android:id="@+id/cranImage"
                android:layout_below="@id/electricityImage"
                android:layout_alignLeft="@id/electricityImage"
                android:padding="5dp"/>

            <TextView 
                style="@style/CodeFont"
                android:id="@+id/item_cran"
                android:text="@string/item_cran"
                android:textSize="14sp"
                android:layout_toLeftOf="@id/cranImage"
                android:layout_below="@id/electricityImage"/>        

                            <View
                android:layout_height="1dip"
                android:background="#FF909090"
                android:layout_below="@id/cranImage"
                android:layout_width="fill_parent"/>                   

            <ImageView 
                android:layout_height="wrap_content"
                android:layout_width="wrap_content" 
                android:id="@+id/slipwayImage"
                android:layout_below="@id/cranImage"
                android:layout_alignLeft="@id/cranImage"
                android:padding="5dp"/> 

            <TextView 
                style="@style/CodeFont"
                android:id="@+id/item_slipway"
                android:text="@string/item_slipway"
                android:textSize="14sp"
                android:layout_toLeftOf="@id/slipwayImage"
                android:layout_below="@id/cranImage"/>  

                        <View
                android:layout_height="1dip"
                android:background="#FF909090"
                android:layout_below="@id/slipwayImage"
                android:layout_width="fill_parent"/>

            <ImageView 
                android:layout_height="wrap_content"
                android:layout_width="wrap_content" 
                android:id="@+id/campingImage"
                android:layout_below="@id/slipwayImage"
                android:layout_alignLeft="@id/slipwayImage"
                android:padding="5dp"/> 

            <TextView 
                style="@style/CodeFont"
                android:id="@+id/item_camping"
                android:text="@string/item_camping"
                android:textSize="14sp"
                android:layout_toLeftOf="@id/campingImage"
                android:layout_below="@id/slipwayImage"/>       

                            <View
                android:layout_height="1dip"
                android:background="#FF909090"
                android:layout_below="@id/campingImage"
                android:layout_width="fill_parent"/>

            <ImageView
                android:layout_height="wrap_content"
                android:layout_width="wrap_content" 
                android:id="@+id/freshWaterImage"
                android:layout_below="@id/campingImage"
                android:layout_alignLeft="@id/campingImage"
                android:padding="5dp"/> 

            <TextView 
                style="@style/CodeFont"
                android:id="@+id/item_freshWater" 
                android:text="@string/item_freshWater"
               android:textSize="14sp"
               android:layout_toLeftOf="@id/freshWaterImage"
                android:layout_below="@id/campingImage"/>  

        </RelativeLayout>   

    </LinearLayout>

</LinearLayout>
</ScrollView>

I am setting an image for the background of a linearlayout that I am using. The problem I am getting is the white border just below the title bar. If I set the background to a color the white border does not appear. Does anybody know what might be causing this.

background image problem

I am loading some content in dynamically but here is the xml

<?xml version="1.0" encoding="utf-8"?>
<android.gesture.GestureOverlayView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/gestures"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gestureStrokeType="single"
    android:eventsInterceptionEnabled="true"
    android:orientation="vertical"
    android:uncertainGestureColor="#00000000"
    android:gestureColor="#00000000">
<ScrollView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">


<LinearLayout android:id="@+id/LinearLayout01"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:padding="20dip"
    android:background="@drawable/background">
<!--     android:background="@drawable/background"> -->


    <TextView 
        android:id="@+id/item_text"
        android:layout_height="wrap_content"
        android:textSize="16sp"
        android:layout_gravity="center"
        android:text="@string/item_text"
        android:textColor="#fffafa"
        android:layout_width="wrap_content"
        android:textStyle="bold"
        android:paddingBottom="10dip"/>

    <LinearLayout
        android:id="@+id/photoLayout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:paddingBottom="20dip"/>     

     <LinearLayout android:id="@+id/LinearLayoutDynamic"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:padding="10dp"
        android:orientation="vertical"
        android:background="@drawable/my_border">

     </LinearLayout>

     <TextView 
        android:id="@+id/item_text1"
        android:layout_height="wrap_content"
        android:paddingTop="20dip"
        android:paddingBottom="10dip"
        android:textSize="16sp"
        android:layout_gravity="center"
        android:text="Besonderheiten"
        android:textColor="#fffafa"
        android:layout_width="wrap_content"
        android:textStyle="bold"/>

    <LinearLayout android:id="@+id/RelativeLayout01"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"

        android:orientation="vertical"
        android:background="@drawable/my_border">

        <RelativeLayout
            android:id="@+id/LinearLayout"
            android:layout_height="fill_parent"
            android:layout_width="fill_parent"
            android:orientation="horizontal">   


            <TextView 
                style="@style/CodeFont"
               android:id="@+id/item_wasteDisposal"
               android:text="@string/item_wasteDisposal"
               android:textSize="14sp"
               android:singleLine="true"/>  

            <ImageView 
                android:layout_height="wrap_content"  
                android:layout_width="wrap_content" 
                android:id="@+id/wasteDisposalImage"
                android:layout_toRightOf="@id/item_wasteDisposal"
                android:padding="5dp"/>

            <View
                android:layout_height="1dip"
                android:background="#FF909090"
                android:layout_below="@id/wasteDisposalImage"
                android:layout_width="fill_parent"/>


            <ImageView
                android:layout_height="wrap_content" 
                android:layout_width="wrap_content" 
                android:id="@+id/internetImage"
                android:layout_below="@id/wasteDisposalImage"
                android:layout_alignLeft="@id/wasteDisposalImage"
                android:padding="5dp"/>

            <TextView 
                style="@style/CodeFont"
                android:id="@+id/item_internet"
                android:text="@string/item_internet"
                android:textSize="14sp"
                android:layout_toLeftOf="@id/internetImage"
                android:layout_below="@id/wasteDisposalImage"/>

            <View
                android:layout_height="1dip"
                android:background="#FF909090"
                android:layout_below="@id/internetImage"
                android:layout_width="fill_parent"/>


            <ImageView 
                android:layout_height="wrap_content" 
                android:layout_width="wrap_content"
                android:id="@+id/overnightStayImage"
                android:layout_below="@id/internetImage"
                android:layout_alignLeft="@id/internetImage"
                android:padding="5dp"/>

            <TextView 
                style="@style/CodeFont"
                android:id="@+id/item_overnightStay"
                android:text="@string/item_overnightStay"
                android:textSize="14sp"
                android:layout_toLeftOf="@id/overnightStayImage"
                android:layout_below="@id/internetImage"/>  

                            <View
                android:layout_height="1dip"
                android:background="#FF909090"
                android:layout_below="@id/overnightStayImage"
                android:layout_width="fill_parent"/>

            <ImageView 
                android:layout_height="wrap_content" 
                android:layout_width="wrap_content" 
                android:id="@+id/toiletImage"
                android:layout_below="@id/overnightStayImage"
                android:layout_alignLeft="@id/overnightStayImage"
                android:padding="5dp"/>

            <TextView 
                style="@style/CodeFont"
                android:id="@+id/item_toilet"
                android:text="@string/item_toilet"
                android:textSize="14sp"
                android:layout_toLeftOf="@id/toiletImage"
                android:layout_below="@id/overnightStayImage"/>

                            <View
                android:layout_height="1dip"
                android:background="#FF909090"
                android:layout_below="@id/toiletImage"
                android:layout_width="fill_parent"/>

            <ImageView 
                android:layout_height="wrap_content"
                android:layout_width="wrap_content" 
                android:id="@+id/electricityImage"
                android:layout_below="@id/toiletImage"
                android:layout_alignLeft="@id/toiletImage"
                android:padding="5dp"/>

            <TextView 
                style="@style/CodeFont"
                android:id="@+id/item_electricity"
                android:text="@string/item_electricity"
                android:textSize="14sp"
                android:layout_toLeftOf="@id/electricityImage"
                android:layout_below="@id/toiletImage"/>                

                        <View
                android:layout_height="1dip"
                android:background="#FF909090"
                android:layout_below="@id/electricityImage"
                android:layout_width="fill_parent"/>

            <ImageView 
                android:layout_height="wrap_content" 
                android:layout_width="wrap_content" 
                android:id="@+id/cranImage"
                android:layout_below="@id/electricityImage"
                android:layout_alignLeft="@id/electricityImage"
                android:padding="5dp"/>

            <TextView 
                style="@style/CodeFont"
                android:id="@+id/item_cran"
                android:text="@string/item_cran"
                android:textSize="14sp"
                android:layout_toLeftOf="@id/cranImage"
                android:layout_below="@id/electricityImage"/>        

                            <View
                android:layout_height="1dip"
                android:background="#FF909090"
                android:layout_below="@id/cranImage"
                android:layout_width="fill_parent"/>                   

            <ImageView 
                android:layout_height="wrap_content"
                android:layout_width="wrap_content" 
                android:id="@+id/slipwayImage"
                android:layout_below="@id/cranImage"
                android:layout_alignLeft="@id/cranImage"
                android:padding="5dp"/> 

            <TextView 
                style="@style/CodeFont"
                android:id="@+id/item_slipway"
                android:text="@string/item_slipway"
                android:textSize="14sp"
                android:layout_toLeftOf="@id/slipwayImage"
                android:layout_below="@id/cranImage"/>  

                        <View
                android:layout_height="1dip"
                android:background="#FF909090"
                android:layout_below="@id/slipwayImage"
                android:layout_width="fill_parent"/>

            <ImageView 
                android:layout_height="wrap_content"
                android:layout_width="wrap_content" 
                android:id="@+id/campingImage"
                android:layout_below="@id/slipwayImage"
                android:layout_alignLeft="@id/slipwayImage"
                android:padding="5dp"/> 

            <TextView 
                style="@style/CodeFont"
                android:id="@+id/item_camping"
                android:text="@string/item_camping"
                android:textSize="14sp"
                android:layout_toLeftOf="@id/campingImage"
                android:layout_below="@id/slipwayImage"/>       

                            <View
                android:layout_height="1dip"
                android:background="#FF909090"
                android:layout_below="@id/campingImage"
                android:layout_width="fill_parent"/>

            <ImageView
                android:layout_height="wrap_content"
                android:layout_width="wrap_content" 
                android:id="@+id/freshWaterImage"
                android:layout_below="@id/campingImage"
                android:layout_alignLeft="@id/campingImage"
                android:padding="5dp"/> 

            <TextView 
                style="@style/CodeFont"
                android:id="@+id/item_freshWater" 
                android:text="@string/item_freshWater"
               android:textSize="14sp"
               android:layout_toLeftOf="@id/freshWaterImage"
                android:layout_below="@id/campingImage"/>  

        </RelativeLayout>   

    </LinearLayout>

</LinearLayout>
</ScrollView>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冷清清 2024-11-14 09:38:09

发布您的图像文件。它是 9-patch png 还是只是一个标准图像文件?如果没有更多信息,我猜测您的图像对于您的空间来说太大了,并且由于某种原因,当它缩小时,它必须在两个方向上缩小,并在顶部创建空白空间。我以前就注意到过这种效果。如果发生这种情况,那么解决方案要么将图像文件的大小调整为更小,以便不必缩小,要么(这可能是首选方法)创建一个非常小的 9 补丁,它将扩展到图像中你想要的。我很难说,但从图片来看,你的图像无论如何都只是纯色,所以如果你选择 9 补丁路线,你可以将其设置为非常小的画布尺寸 10 x 10 像素或其他尺寸。并且它知道如何扩展它以填充所需的任何空间。

另一种判断是否发生这种情况的方法是在屏幕更大的设备上运行您的应用程序。那么它就不必缩小图像文件,因此不应在顶部显示空白区域

Post your image file. And is it a 9-patch png or just a standard image file? Without more info my guess that your image is too big for your space, and for some reason when it shrinks it down it has to shrink in both directions and it creates blank space at the top. I have noticed this effect before. If that is what is happening then solutions would be either resize the image file to smaller so that it won't have to shrink, or (and this is probably the prefered way) create a a very small 9-patch that will expand into the image you want. It is hard for me to tell but it looks like from the picture your image is just a solid color anyway, so if you went the 9-patch route you could make it a very small canvas size 10 x 10 pixels or something. and it would know how to expand it to fill any space required.

Another way to tell if this is what is going on is run your app on something with a bigger screen. Then it won't have to shrink the image file and thus should not show the blank space at the top

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文