Android LinearLayout:分隔线不会显示

Jam*_*uth 5 android divider android-linearlayout xml-drawable android-drawable

我正在尝试设置要在我的应用程序列表中使用的分隔符。我已经为“diceddivider”制作了 XML 代码,如下所示

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line">
<stroke
   android:width="1px"
   android:color="@color/divider_Color"
   />

</shape>
Run Code Online (Sandbox Code Playgroud)

然后我试图将它设置为我的 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();
}
Run Code Online (Sandbox Code Playgroud)

尽管如此,该应用程序没有显示分隔符。我什至尝试将它直接嵌入到 XML 中,但没有任何运气。

我对 Android 编码很陌生。知道我哪里出错了吗?

Jav*_*uez -3

您必须将分隔线设置为 listView,而不是 LinearLayout