2009-12-17 145 views
13

的顶部绘制一个边框遵循了渐变分隔的例子: http://www.connorgarvey.com/blog/?p=34如何在线性布局

我曾试过把我的线性布局的底部画一条水平线。

这里是我的线性布局文件:

 <LinearLayout android:id="@+id/test" android:layout_width="fill_parent" 
      android:layout_height="wrap_content> 

<ImageView android:id="@+id/icon1" 
    android:layout_width="32dip" 
    android:layout_height="32dip" 
/> 

而且我确实添加了

<View 
android:background="@drawable/black_white_gradient" 
android:layout_width="fill_parent" 
android:layout_height="1dp" 
android:layout_above="@id/test" 
/> 

但我看不出有任何线在的LinearLayout的顶部。而当我去层次视图,看看他查看(用于园艺分离器),在的getWidth()为0时的getHeight()为1

能否请你告诉我,我错过了什么?

谢谢。

+0

任何人有任何想法? – n179911 2009-12-18 04:59:27

回答

2

我认为在父线性布局视图中可能缺少方向;

<LinearLayout android:orientation="vertical" 

或者,如果你使用的不是LinearLayout中的RelativeLayout,你可以设置的layout_alignParentBottom;

<View android:layout_alignParentBottom="true" 
4

随着你发布的代码,它完美地fine.But的事实大小1dp可能无法显示它。增加尺寸或只想要一个线使用默认的行绘制于Android

android:background="@android:drawable/divider_horizontal_bright" 
// this for white background only 

我希望这将有助于你得到你想要

1

如果身高1DP这将是不可见的。尝试2DP代替:

<View android:background="@drawable/black_white_gradient" android:layout_width="fill_parent" android:layout_height="2dp" android:layout_above="@id/test" />

1

的黑色边框,如果大小至少2DP才会显示。尝试删除边界,并设置纯色黑:

<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
    <solid android:color="#000" /> 
</shape> 

比你可以再次使用1DP的高度。