How to add (vertical) divider to a horizontal LinearLayout?

后端 未结 11 637
有刺的猬
有刺的猬 2020-11-27 11:36

I\'m trying to add a divider to a horizontal linear layout but am getting nowhere. The divider just doesn\'t show. I am a total newbie with Android.

This is my layou

11条回答
  •  离开以前
    2020-11-27 12:05

    Update: pre-Honeycomb using AppCompat

    If you are using the AppCompat library v7 you may want to use the LinearLayoutCompat view. Using this approach you can use drawable dividers on Android 2.1, 2.2 and 2.3.

    Example code:

    
    

    drawable/divider.xml: (divider with some padding on the top and bottom)

    
    
        
            
            
        
    
    

    Very important note: The LinearLayoutCompat view does not extend LinearLayout and therefor you should not use the android:showDividers or android:divider properties but the custom ones: app:showDividers and app:divider. In code you should also use the LinearLayoutCompat.LayoutParams not the LinearLayout.LayoutParams!

提交回复
热议问题