Android 布局中的边框具有意外的空间
我有一个带边框的布局。我的问题是,在边框和其他布局之间有一个空间,但我不知道它来自哪里 我的布局看起来像Android 布局中的边框具有意外的空间,android,android-layout,android-drawable,Android,Android Layout,Android Drawable,我有一个带边框的布局。我的问题是,在边框和其他布局之间有一个空间,但我不知道它来自哪里 我的布局看起来像 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" style="@style/BackgroundLayout" android:layout_width="match_parent"
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/BackgroundLayout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<!-- Layout come's here :) -->
</LinearLayout>
背景布局的样式如下所示:
<style name="BackgroundLayout">
<item name="android:background">@drawable/frame_border</item>
<item name="android:orientation">vertical</item>
<item name="android:paddingLeft">@dimen/line_width</item>
<item name="android:paddingRight">@dimen/line_width</item>
</style>
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape android:shape="rectangle" >
<stroke
android:width="@dimen/line_width"
android:color="@color/background_color" />
<solid android:color="@color/background_color" />
</shape>
</item>
<item
android:left="@dimen/line_width"
android:right="@dimen/line_width"
android:bottom="@dimen/line_width">
<bitmap android:src="@drawable/background" android:gravity="fill_horizontal|fill_vertical" />
</item>
</layer-list>
@可拉延/框边
垂直的
@尺寸/线宽
@尺寸/线宽
框架_uBorder(是一个可绘制的.xml)看起来如下:
<style name="BackgroundLayout">
<item name="android:background">@drawable/frame_border</item>
<item name="android:orientation">vertical</item>
<item name="android:paddingLeft">@dimen/line_width</item>
<item name="android:paddingRight">@dimen/line_width</item>
</style>
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape android:shape="rectangle" >
<stroke
android:width="@dimen/line_width"
android:color="@color/background_color" />
<solid android:color="@color/background_color" />
</shape>
</item>
<item
android:left="@dimen/line_width"
android:right="@dimen/line_width"
android:bottom="@dimen/line_width">
<bitmap android:src="@drawable/background" android:gravity="fill_horizontal|fill_vertical" />
</item>
</layer-list>
@dimen/线宽的大小为5dp
我样式中的填充与边框大小相同。所以应该有任何区别(希望如此)
编辑:
为了说明这个问题,我创建了一个新视图(见下文)。背景保持不变。视图(线性布局为黑色区域):
解决方案
到目前为止,我的解决方案是将背景图像位置从@dimen/线宽(5dp)更改为5.5dp。虽然不令人满意,但它确实有效
<item
android:left="5.5dp"
android:right="5.5dp"
android:bottom="5.5dp">
<bitmap android:src="@drawable/background" android:gravity="fill_vertical|fill_horizontal"/>
</item>
编辑:不是100%确定,但可能是android股票分割器的问题。下面的代码适合我
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/border"
android:padding="4dip"
tools:context=".MainActivity" >
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:divider="@drawable/horizontal_divider"
android:dividerHeight="4dp" >
</ListView>
</LinearLayout>
background.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid android:color="#fd9f8d" />
<stroke android:width="4dip" android:color="#BDBCBC"/>
</shape>
水平分隔符.xml
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line">
<stroke
android:color="#FFFFFF"
android:width="2dip"
/>
<size
android:height="1dip"
/>
</shape>
它来自:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/BackgroundLayout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<!-- Layout come's here :) -->
</LinearLayout>
你的风格里有填充物。检查并发布结果。填充的大小应与边框的大小相同(请参见drawable.xml)。如果希望子元素(我假设是列表视图)完全“匹配父元素”可能与股票分割器有关,则仍然不需要在父元素上填充?请参阅编辑。我使用自定义android分隔符。我也有其他观点的问题。我编辑了我的问题,并添加了另一个example.sry,因为我写了这么多评论。我找到了解决方案,请参阅我的编辑。这并不令人满意,但效果很好。填充物的大小与蓝色边框的大小相同。因此,不应该有任何空间。