Android draw a Horizontal line between views

前端 未结 15 2257
不知归路
不知归路 2020-12-12 12:28

I have My Layout like below:




        
相关标签:
15条回答
  • 2020-12-12 13:16

    which work for me is

        <view
        android:layout_below="@+id/kaimla_number"
        android:layout_width="match_parent"
        android:layout_height="3dp"
        android:background="@color/golden"></view>
    
    0 讨论(0)
  • 2020-12-12 13:23

    You should use the new lightweight View Space to draw dividers. Your layout will load faster if you will use Space instead of View.

    Horizontal divider:

    <android.support.v4.widget.Space
            android:layout_height="1dp"
            android:layout_width="match_parent" /> 
    

    Vertical divider:

    <android.support.v4.widget.Space
            android:layout_height="match_parent"
            android:layout_width="1dp" />
    

    You can also add a background:

    <android.support.v4.widget.Space
            android:layout_height="match_parent"
            android:layout_width="1dp"
            android:background="?android:attr/listDivider"/>
    

    Usage example:

    ....
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="One"/>
    
    <android.support.v4.widget.Space
        android:layout_height="match_parent"
        android:layout_width="1dp"
        android:background="?android:attr/listDivider"/>
    
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Two"/>
    
    <android.support.v4.widget.Space
        android:layout_height="match_parent"
        android:layout_width="1dp"
        android:background="?android:attr/listDivider"/>
    
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Three"/>
    ....
    

    In order to use Space you should add the dependency in your build.gradle:

    dependencies {
        compile 'com.android.support:support-v4:22.1.+'
    }
    

    Documentation https://developer.android.com/reference/android/support/v4/widget/Space.html

    0 讨论(0)
  • 2020-12-12 13:23

    You can put this view between your views to imitate the line

    <View
      android:layout_width="fill_parent"
      android:layout_height="2dp"
      android:background="#c0c0c0"/>
    
    0 讨论(0)
提交回复
热议问题