android - 如何在线性布局顶部绘制边框

标签 android

我已经按照渐变分隔线中的示例进行操作: 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 的顶部没有看到任何一行。当我转到层次结构 View 并看到他的 View (对于短分隔符)时,getWidth() 为 0 而 getHeight() 为 1。

你能告诉我我错过了什么吗?

谢谢。

最佳答案

使用您发布的代码,它非常好。但是尺寸为 1dp 的事实可能无法显示。增加大小或只需要一条线使用可从 android 绘制的默认线

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

我希望这能帮助你得到你想要的

关于android - 如何在线性布局顶部绘制边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1923480/

相关文章:

android - 如何更改 ListView 的颜色,交替行颜色?

安卓 repo 变更日志

android - 确定 android 上的横幅广告尺寸

android - 从 Google Play 安装时将参数传递给应用

android - 从 View 寻呼机内部的 fragment 中获取 Activity 返回 null

android - 在一行中将图像与文本基线对齐

Android View 比较两个 View 是否相等

android - 我们的应用程序是否加载了包含的库文件中的所有类?

android - C 和 Arduino 之间的通信

android - 弹出窗口不显示