I'm trying to set a divider to be used in a list for my app. I have made the XML code for the "dicedivider" as shown below
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line">
<stroke
android:width="1px"
android:color="@color/divider_Color"
/>
</shape>
Then I am trying to set it as the divider drawable for my LinearLayout as shown below
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
diceCount = 0;
diceList = (LinearLayout) this.findViewById(R.id.main_Dice_List);
diceList.setShowDividers(LinearLayout.SHOW_DIVIDER_MIDDLE);
diceList.setDividerDrawable(this.getResources().getDrawable(R.drawable.dicedivider));
diceList.setDividerPadding(5);
addDice();
}
Regardless of this though the app shows no dividers. I've even tried embedding it directly into the XML and not had any luck.
I'm very new at Android coding. Any idea where I'm going wrong?
Create a file mydivider.xml inside res/drawable and put the following shape:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<size android:width="1dip" />
<solid android:color="#ffffff" />
</shape>
add the shape as divider for your layout
<LinearLayout android:id="@+id/linearlayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:divider="@drawable/mydivider"
android:showDividers="middle"
android:dividerPadding="22dp">
</LinearLayout>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With