我正在尝试设置一个分隔线,用于我的应用程序中的列表。我已经制作了“dicedivider”的XML代码,如下所示:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line">
<stroke
android:width="1px"
android:color="@color/divider_Color"
/>
</shape>
我试图将它设置为LinearLayout的分隔符可绘制对象,如下所示:
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();
}
然而,不管怎样,应用程序未显示任何分隔线。我甚至尝试将其直接嵌入XML中,但没有成功。
我在Android编码方面非常新手。您有什么想法我出了什么问题吗?
android:showDividers
属性! - Fattie