欢迎来到代码驿站!

Android代码

当前位置:首页 > 移动开发 > Android代码

android利用xml实现分割线

时间:2021-04-21 09:39:47|栏目:Android代码|点击:

因为没有美工, 所以只能自己动手了。

在layout文件夹里的xml 写

方法1:在layout里面的布局xml 文件里加上面的代码

 <View
 android:layout_width="match_parent"
 android:layout_height="1dp"
 android:background="@color/orange_normal" />

效果图

在drawable文件夹里用 shape line 或 rectangle 先画线

方法2:在drawable里面用shape新建一个xml

然后在 layout 里的布局文件里引用

这种方法 可以 多处引用同一个 line 样式

<!-- drawable/line_my.xml -->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
 android:shape="line" >

 <stroke android:color="@color/orange_normal" />

</shape>

或者用填充的矩形实现

<shape xmlns:android="http://schemas.android.com/apk/res/android"
 android:shape="rectangle" >

 <solid android:color="@color/orange_normal" />

 <size
  android:height="1dp"
  android:width="100dp" />

</shape>

Note
android:width=”100dp” 不能赋值为 “match_parent”
在layout/bomb_fragment.xml 里面引用

 <TextView
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:background="@drawable/line_my" />

希望本文所述对大家学习Android软件编程有所帮助。

上一篇:Android倒计时控件 Splash界面5秒自动跳转

栏    目:Android代码

下一篇:Android编程开发录音和播放录音简单示例

本文标题:android利用xml实现分割线

本文地址:http://www.codeinn.net/misctech/105935.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有