Android:在布局中绘制垂直线
我试图在列表(回收器视图)的行布局中绘制垂直线。行布局的内容增加时,行应与布局左侧对齐,边距为20dp,行高度应为自动。行布局左侧对齐的垂直线也应增加 我试图通过在drawable文件夹中绘制垂直线来添加线条,并将其添加到布局的背景中。但问题是,这条线只占一半 可绘制:垂直线.xmlAndroid:在布局中绘制垂直线,android,android-layout,Android,Android Layout,我试图在列表(回收器视图)的行布局中绘制垂直线。行布局的内容增加时,行应与布局左侧对齐,边距为20dp,行高度应为自动。行布局左侧对齐的垂直线也应增加 我试图通过在drawable文件夹中绘制垂直线来添加线条,并将其添加到布局的背景中。但问题是,这条线只占一半 可绘制:垂直线.xml <rotate xmlns:android="http://schemas.android.com/apk/res/android" android:fromDegrees="90" android:toDe
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="90"
android:toDegrees="90"
android:pivotX="10">
<shape
android:shape="line">
<stroke
android:width="1dp"
android:color="#ff00ff"
/>
</shape>
布局
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/black_two">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:background="@drawable/vertical_line"
>
<TextView
android:layout_width="match_parent"
android:layout_height="100dp"
android:text="text"
android:textColor="@color/white"/>
</RelativeLayout>
请帮助我使用自动高度在布局左侧绘制一条线您可以使用
视图
作为垂直线,而不是形状:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:layout_marginLeft="20dp"
android:background="#ff00ff"/>
<TextView
android:layout_width="match_parent"
android:layout_height="100dp"
android:text="text"
android:textColor="@color/white"/>
</LinearLayout>
您可以将
视图
用于垂直线,而不是形状:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:layout_marginLeft="20dp"
android:background="#ff00ff"/>
<TextView
android:layout_width="match_parent"
android:layout_height="100dp"
android:text="text"
android:textColor="@color/white"/>
</LinearLayout>
您真的需要一个可绘制的xml来绘制垂直线吗?因为您也可以仅使用视图来实现这一点……您的父级RelativeLayout
高度是“wrap\u content”,将其更改为“match\u parent”,这样,如果我们使用如何将该高度设置为wrap,它将在整个屏幕@Aaron上画一条线_content@AkshayKatariya我用这个布局作为我列表的行项目,那么,如何更改行父布局以匹配\u父?。如果是这样,则1行占用视图的全部高度。@BinilSurendran如果使用,只需将高度设置为与父级匹配即可。您真的需要一个可绘制的xml来绘制垂直线吗?因为您也可以仅使用视图来实现这一点……您的父级RelativeLayout
高度是“wrap\u content”,将其更改为“match\u parent”,这样,如果我们使用如何将该高度设置为wrap,它将在整个屏幕@Aaron上画一条线_content@AkshayKatariya我用这个布局作为我列表的行项目,那么,如何更改行父布局以匹配\u父?。如果是这样,则1行占用视图的全部高度。@BinilSurendran如果使用,只需将高度设置为与父级匹配即可。谢谢,伙计,我尝试了与父级布局相同的方法,如TextView
高度更改为wrap\u content
,它仍将工作-将调整视图的高度以匹配其父级,这受TextView
的影响。谢谢你,我尝试了与父级布局相同的方法,如,但正如你所说的,在改变后,这是成功。不客气。如果将TextView
高度更改为wrap\u content
,它仍将工作-将调整视图
高度以匹配其父视图,这受TextView
的影响。