I’m interested in adding dividers to a LinearLayout’s children dynamically. I see in the docs that LinearLayout contains a CONST “SHOW_DIVIDER_MIDDLE” along with get and set divider methods. Can someone show me how I implement it? Thanks!
“This does not work”
layout xml:
<LinearLayout android:id="@+id/bar"
android:orientation="horizontal"
android:layout_height="40dip" android:layout_width="fill_parent"
android:background="@drawable/ab_background_gradient" android:gravity="right|center_vertical">
<!-- sort button -->
<Button android:id="@+id/sortBtn" android:background="@drawable/defaultt"
android:layout_width="30dip" android:layout_height="30dip" android:onClick="sortThis" />
<!-- add button -->
<Button android:id="@+id/addBtn" android:background="@drawable/defaultt"
android:layout_width="30dip" android:layout_height="30dip" android:onClick="addThis" />
</LinearLayout>
main:
...
private void setupViews() {
//bar
mBar = (LinearLayout) findViewById(R.id.bar);
mBar.setDividerDrawable(R.drawable.divider);
}
You need to convert the Resource id you get back from
R.drawable.dividerinto a Drawable object, ala:This assumes you’ve got a file named ‘divider.jpg’ (or similar) in your resources directory.