Android draw a Horizontal line between views

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

I have My Layout like below:




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

    ----> Simple one

     <TextView
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="#c0c0c0"
        android:id="@+id/your_id"
        android:layout_marginTop="160dp" />
    
    0 讨论(0)
  • 2020-12-12 13:03

    It will draw Silver gray colored Line between TextView & ListView

    <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="match_parent"
        android:layout_height="2dp"
        android:background="#c0c0c0"/>
    
    <ListView
        android:id="@+id/list1"
        android:layout_width="350dp"
        android:layout_height="50dp" />
    
    0 讨论(0)
  • 2020-12-12 13:07

    Creating it once and using it wherever needed is a good idea. Add this in your styles.xml:

    <style name="Divider">
        <item name="android:layout_width">match_parent</item>
        <item name="android:layout_height">1dp</item>
        <item name="android:background">?android:attr/listDivider</item>
    </style>
    

    and add this in your xml code, where a line divider is needed:

    <View style="@style/Divider"/>
    

    Originally answered by toddles_fp to this question: Android Drawing Separator/Divider Line in Layout?

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

    Try this

    <View
        android:layout_width="match_parent"
        android:layout_height="2dp"
        android:background="?android:attr/listDivider"/>
    
    0 讨论(0)
  • 2020-12-12 13:09

    If you does not want to use an extra view just for underlines. Add this style on your textView.

    style="?android:listSeparatorTextViewStyle"
    

    Just down side is it will add extra properties like

    android:textStyle="bold"
    android:textAllCaps="true"
    

    which you can easily override.

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

    Create Horizontal line

    If your are using TextView and then you want to put a Line then use View this way and you can use any color like Blue, Red or black mentioning background color.

     <view
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:background="@android:color/black"></view>
    

    0 讨论(0)
提交回复
热议问题