在LinearLayout中背景图像 [英] Background Image in Linearlayout

查看:138
本文介绍了在LinearLayout中背景图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设置的图像,我使用的LinearLayout的背景。我得到的问题是仅低于标题栏中的白色边框。如果我设置背景色的白色边框不会出现。有谁知道什么可能导致这一点。

我加载在动态的一些内容,但这里是XML

 < XML版本=1.0编码=UTF-8&GT?;
< android.gesture.GestureOverlayView
    的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:ID =@ + ID /手势
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT
    机器人:gestureStrokeType =单
    机器人:eventsInterceptionEnabled =真
    机器人:方向=垂直
    机器人:uncertainGestureColor =#00000000
    机器人:gestureColor =#00000000>
<滚动型
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT>


<的LinearLayout机器人:ID =@ + ID / LinearLayout01
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT
    机器人:方向=垂直
    机器人:填充=20dip
    机器人:背景=@可绘制/背景>
<  - 安卓!后台=@可绘制/背景> - >


    <的TextView
        机器人:ID =@ + ID / item_text
        机器人:layout_height =WRAP_CONTENT
        机器人:TEXTSIZE =16SP
        机器人:layout_gravity =中心
        机器人:文本=@字符串/ item_text
        机器人:文字颜色=#fffafa
        机器人:layout_width =WRAP_CONTENT
        机器人:TEXTSTYLE =黑体
        机器人:paddingBottom会=10dip/>

    <的LinearLayout
        机器人:ID =@ + ID / photoLayout
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =WRAP_CONTENT
        机器人:paddingBottom会=20dip/>

     <的LinearLayout机器人:ID =@ + ID / LinearLayoutDynamic
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =FILL_PARENT
        机器人:填充=10dp
        机器人:方向=垂直
        机器人:背景=@可绘制/ my_border>

     < / LinearLayout中>

     <的TextView
        机器人:ID =@ + ID / item_text1
        机器人:layout_height =WRAP_CONTENT
        机器人:paddingTop =20dip
        机器人:paddingBottom会=10dip
        机器人:TEXTSIZE =16SP
        机器人:layout_gravity =中心
        机器人:文本=Besonderheiten
        机器人:文字颜色=#fffafa
        机器人:layout_width =WRAP_CONTENT
        机器人:TEXTSTYLE =黑体/>

    <的LinearLayout机器人:ID =@ + ID / RelativeLayout01
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =FILL_PARENT

        机器人:方向=垂直
        机器人:背景=@可绘制/ my_border>

        < RelativeLayout的
            机器人:ID =@ + ID / LinearLayout中
            机器人:layout_height =FILL_PARENT
            机器人:layout_width =FILL_PARENT
            机器人:方向=横向>


            <的TextView
                风格=@风格/ codeFONT
               机器人:ID =@ + ID / item_wasteDisposal
               机器人:文本=@字符串/ item_wasteDisposal
               机器人:TEXTSIZE =14sp
               机器人:单线=真/>

            < ImageView的
                机器人:layout_height =WRAP_CONTENT
                机器人:layout_width =WRAP_CONTENT
                机器人:ID =@ + ID / wasteDisposalImage
                机器人:layout_toRightOf =@ ID / item_wasteDisposal
                机器人:填充=5DP/>

            <查看
                机器人:layout_height =1dip
                机器人:后台=#FF909090
                机器人:layout_below =@ ID / wasteDisposalImage
                机器人:layout_width =FILL_PARENT/>


            < ImageView的
                机器人:layout_height =WRAP_CONTENT
                机器人:layout_width =WRAP_CONTENT
                机器人:ID =@ + ID / internetImage
                机器人:layout_below =@ ID / wasteDisposalImage
                机器人:layout_alignLeft =@ ID / wasteDisposalImage
                机器人:填充=5DP/>

            <的TextView
                风格=@风格/ codeFONT
                机器人:ID =@ + ID / item_internet
                机器人:文本=@字符串/ item_internet
                机器人:TEXTSIZE =14sp
                机器人:layout_toLeftOf =@ ID / internetImage
                机器人:layout_below =@ ID / wasteDisposalImage/>

            <查看
                机器人:layout_height =1dip
                机器人:后台=#FF909090
                机器人:layout_below =@ ID / internetImage
                机器人:layout_width =FILL_PARENT/>


            < ImageView的
                机器人:layout_height =WRAP_CONTENT
                机器人:layout_width =WRAP_CONTENT
                机器人:ID =@ + ID / overnightStayImage
                机器人:layout_below =@ ID / internetImage
                机器人:layout_alignLeft =@ ID / internetImage
                机器人:填充=5DP/>

            <的TextView
                风格=@风格/ codeFONT
                机器人:ID =@ + ID / item_overnightStay
                机器人:文本=@字符串/ item_overnightStay
                机器人:TEXTSIZE =14sp
                机器人:layout_toLeftOf =@ ID / overnightStayImage
                机器人:layout_below =@ ID / internetImage/>

                            <查看
                机器人:layout_height =1dip
                机器人:后台=#FF909090
                机器人:layout_below =@ ID / overnightStayImage
                机器人:layout_width =FILL_PARENT/>

            < ImageView的
                机器人:layout_height =WRAP_CONTENT
                机器人:layout_width =WRAP_CONTENT
                机器人:ID =@ + ID / toiletImage
                机器人:layout_below =@ ID / overnightStayImage
                机器人:layout_alignLeft =@ ID / overnightStayImage
                机器人:填充=5DP/>

            <的TextView
                风格=@风格/ codeFONT
                机器人:ID =@ + ID / item_toilet
                机器人:文本=@字符串/ item_toilet
                机器人:TEXTSIZE =14sp
                机器人:layout_toLeftOf =@ ID / toiletImage
                机器人:layout_below =@ ID / overnightStayImage/>

                            <查看
                机器人:layout_height =1dip
                机器人:后台=#FF909090
                机器人:layout_below =@ ID / toiletImage
                机器人:layout_width =FILL_PARENT/>

            < ImageView的
                机器人:layout_height =WRAP_CONTENT
                机器人:layout_width =WRAP_CONTENT
                机器人:ID =@ + ID / electricityImage
                机器人:layout_below =@ ID / toiletImage
                机器人:layout_alignLeft =@ ID / toiletImage
                机器人:填充=5DP/>

            <的TextView
                风格=@风格/ codeFONT
                机器人:ID =@ + ID / item_electricity
                机器人:文本=@字符串/ item_electricity
                机器人:TEXTSIZE =14sp
                机器人:layout_toLeftOf =@ ID / electricityImage
                机器人:layout_below =@ ID / toiletImage/>

                        <查看
                机器人:layout_height =1dip
                机器人:后台=#FF909090
                机器人:layout_below =@ ID / electricityImage
                机器人:layout_width =FILL_PARENT/>

            < ImageView的
                机器人:layout_height =WRAP_CONTENT
                机器人:layout_width =WRAP_CONTENT
                机器人:ID =@ + ID / cranImage
                机器人:layout_below =@ ID / electricityImage
                机器人:layout_alignLeft =@ ID / electricityImage
                机器人:填充=5DP/>

            <的TextView
                风格=@风格/ codeFONT
                机器人:ID =@ + ID / item_cran
                机器人:文本=@字符串/ item_cran
                机器人:TEXTSIZE =14sp
                机器人:layout_toLeftOf =@ ID / cranImage
                机器人:layout_below =@ ID / electricityImage/>

                            <查看
                机器人:layout_height =1dip
                机器人:后台=#FF909090
                机器人:layout_below =@ ID / cranImage
                机器人:layout_width =FILL_PARENT/>

            < ImageView的
                机器人:layout_height =WRAP_CONTENT
                机器人:layout_width =WRAP_CONTENT
                机器人:ID =@ + ID / slipwayImage
                机器人:layout_below =@ ID / cranImage
                机器人:layout_alignLeft =@ ID / cranImage
                机器人:填充=5DP/>

            <的TextView
                风格=@风格/ codeFONT
                机器人:ID =@ + ID / item_slipway
                机器人:文本=@字符串/ item_slipway
                机器人:TEXTSIZE =14sp
                机器人:layout_toLeftOf =@ ID / slipwayImage
                机器人:layout_below =@ ID / cranImage/>

                        <查看
                机器人:layout_height =1dip
                机器人:后台=#FF909090
                机器人:layout_below =@ ID / slipwayImage
                机器人:layout_width =FILL_PARENT/>

            < ImageView的
                机器人:layout_height =WRAP_CONTENT
                机器人:layout_width =WRAP_CONTENT
                机器人:ID =@ + ID / campingImage
                机器人:layout_below =@ ID / slipwayImage
                机器人:layout_alignLeft =@ ID / slipwayImage
                机器人:填充=5DP/>

            <的TextView
                风格=@风格/ codeFONT
                机器人:ID =@ + ID / item_camping
                机器人:文本=@字符串/ item_camping
                机器人:TEXTSIZE =14sp
                机器人:layout_toLeftOf =@ ID / campingImage
                机器人:layout_below =@ ID / slipwayImage/>

                            <查看
                机器人:layout_height =1dip
                机器人:后台=#FF909090
                机器人:layout_below =@ ID / campingImage
                机器人:layout_width =FILL_PARENT/>

            < ImageView的
                机器人:layout_height =WRAP_CONTENT
                机器人:layout_width =WRAP_CONTENT
                机器人:ID =@ + ID / freshWaterImage
                机器人:layout_below =@ ID / campingImage
                机器人:layout_alignLeft =@ ID / campingImage
                机器人:填充=5DP/>

            <的TextView
                风格=@风格/ codeFONT
                机器人:ID =@ + ID / item_freshWater
                机器人:文本=@字符串/ item_freshWater
               机器人:TEXTSIZE =14sp
               机器人:layout_toLeftOf =@ ID / freshWaterImage
                机器人:layout_below =@ ID / campingImage/>

        < / RelativeLayout的>

    < / LinearLayout中>

< / LinearLayout中>
< /滚动型>
 

解决方案

发表您的图像文件。而且它是一个9补丁PNG或只是一个标准的图像文件?没有更多的信息我猜,你的形象是太大的空间,由于某种原因,当它收缩下来,它在两个方向上收缩,并在上面创建的空白。我以前已经注意到这种影响。如果这是正在发生的事情则解将是任一图像文件的大小调整为更小的,以便它不会有萎缩,或(这大概是prefered方式)营造出非常小的9-补丁,将扩大成图像,你想要的。这是我很难说,但它看起来像从画面图像只是一个纯色无论如何,所以如果你去了9个补丁的路线,你可以把它一个非常小的画布大小10×10像素或什么的。和它会知道如何扩展它来填充所需的任何空间。

另一种方式来告诉我们,如果这是在是东西在更大的屏幕上运行你的应用程序是怎么回事。然后,它不会有缩小图像文件,因此在顶部应不显示空白

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.

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>

解决方案

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

这篇关于在LinearLayout中背景图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆