我想在布局的中间画一条线,并使用它作为其他项目的分隔符,如TextView。有没有一个好的小部件。我真的不想使用图像,因为它很难匹配其他组件到它。我也想让它有相对的位置。谢谢
当前回答
将此添加到你想要分隔符的布局中(修改属性以适应你的需要):
<ImageView
xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@android:drawable/divider_horizontal_dark"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingBottom="2dp"
android:paddingTop="2dp" />
其他回答
简单的方法:
垂直分割线:
< View =“@style / Divider风格。垂直" - >
水平分割线:
< View =“@style / Divider风格。水平" - >
这都是对的!
把这个放在res>values>styles.xml中
<style name="Divider">
<item name="android:background">?android:attr/listDivider</item> //you can give your color here. that will change all divider color in your app.
</style>
<style name="Divider.Horizontal" parent="Divider">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">1dp</item> // You can change thickness here.
</style>
<style name="Divider.Vertical" parent="Divider">
<item name="android:layout_width">1dp</item>
<item name="android:layout_height">match_parent</item>
</style>
简单的解决方案就是在你的布局中添加这段代码,并将'Id_of__view_present_above'替换为视图的id,下面你需要分隔符。
<TextView
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#c0c0c0"
android:id="@+id/your_id"
android:layout_marginTop="16dp"
android:layout_below="@+id/Id_of__view_present_above"
/>
这是你的答案,这是一个在控件之间画线的例子。
<TextView
android:id="@+id/textView1"
style="@style/behindMenuItemLabel1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="1dp"
android:text="FaceBook Feeds" />
<View
android:layout_width="fill_parent"
android:layout_height="2dp"
android:background="#d13033"/>
<ListView
android:id="@+id/list1"
android:layout_width="350dp"
android:layout_height="50dp" />
这段代码在两个控件之间画线…
你可以在第一个TextView之后使用<View>元素。
<View
android:layout_marginTop="@dimen/d10dp"
android:id="@+id/view1"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#c0c0c0"/>
我通常使用这段代码添加水平线:
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@android:color/darker_gray"/>
若要添加垂直分隔符,请切换layout_width和layout_height值
推荐文章
- 以编程方式将EditText的输入类型从PASSWORD更改为NORMAL,反之亦然
- 如何在隐藏和查看密码之间切换
- 在Android上调整一个大的位图文件到缩放输出文件
- 如何更改Android版本和代码版本号?
- Android Studio突然无法解析符号
- 应用程序重新启动而不是恢复
- 如何设置整个应用程序在纵向模式?
- Android中文本的阴影效果?
- 以编程方式设置TextView的布局权重
- Android -如何覆盖“后退”按钮,所以它不完成()我的活动?
- 如何从通知点击发送参数到一个活动?
- 导航目标xxx对于这个NavController是未知的
- 使用ConstraintLayout均匀间距的视图
- 文件google-services错误。模块根文件夹中缺少Json。谷歌服务插件没有它就不能正常工作。
- 如何以编程方式创建ColorStateList ?