我想在android应用程序的两个视图之间添加分隔线

我想在android应用程序的两个视图之间添加分隔线,android,android-layout,Android,Android Layout,我想添加分隔符(水平或垂直两个视图之间的平滑透明线)如何实现这一点这是我的示例代码。我需要在用户名和密码(水平)之间以及用户图标和用户名提示(垂直)之间添加水平线 只需在userName和passowrd之间创建另一个视图即可 <View android:layout_width="match_parent" android:layout_height="2dp" android:color="@color/divider_color" android:id="@+id/divid

我想添加分隔符(水平或垂直两个视图之间的平滑透明线)如何实现这一点这是我的示例代码。我需要在用户名和密码(水平)之间以及用户图标和用户名提示(垂直)之间添加水平线


只需在userName和passowrd之间创建另一个视图即可

<View 
android:layout_width="match_parent" 
android:layout_height="2dp"
 android:color="@color/divider_color"
 android:id="@+id/divider" />

在用户名和密码的两个线性布局之间,使用以下内容:

<View
        android:id="@+id/line"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="@color/black"/>

将下面的代码制作成可绘制文件,用于分隔线,并在任何需要的地方使用,还可以根据您的选择更改颜色

<View xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="0.7dp"
    android:background="#ebebeb" />

您可以使用高度(或宽度,如果垂直)为1dp的
视图标签在要分割的视图之间添加分隔符:

<View
 android:id="@+id/line"
 android:layout_width="match_parent"
 android:layout_height="1dp"
 android:background="@color/yourColor/>
水平线的

<LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="username"
            android:id="@+id/username"
            android:textColor="#bbc"
            />
        <View
            android:layout_width="0.5dp"
            android:layout_height="match_parent"
            android:background="#ebebeb"
            android:layout_margin="@dimen/margin_5"/>
        <EditText
            android:layout_width="300dp"
            android:layout_height="wrap_content"
            android:hint="usr_name"
            android:textColorHint="#bbc"
            android:backgroundTint="@android:color/transparent"
            android:textColor="@android:color/white"/>
    </LinearLayout>

垂直线

    <View
        android:layout_width="match_parent"
        android:layout_height="0.5dp"
        android:background="#cd2121"
        android:layout_margin="@dimen/margin_5"/>
    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/text_10">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="password"
            android:id="@+id/password"
            android:textColor="#bbc"
            />
        <View
            android:layout_width="0.5dp"
            android:layout_height="match_parent"
            android:background="your color"
            android:layout_margin="@dimen/margin_5"/>
        <EditText
            android:layout_width="300dp"
            android:layout_height="wrap_content"
            android:hint="password"
            android:textColorHint="#bbc"
            android:backgroundTint="@android:color/transparent"
            android:textColor="@android:color/white"/>
    </LinearLayout>

尝试下面的代码

<View xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:background="#cd2121" />


在询问此类问题之前,请先使用谷歌搜索。请尝试至少在您身边查找一次。
<View xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:background="#cd2121" />