Android LinearLayout:Dividers赢了';不显示
我正在尝试设置一个分隔符,以便在我的应用程序列表中使用。我已经为“DiceDictor”编写了XML代码,如下所示Android LinearLayout:Dividers赢了';不显示,android,android-linearlayout,android-drawable,divider,xml-drawable,Android,Android Linearlayout,Android Drawable,Divider,Xml Drawable,我正在尝试设置一个分隔符,以便在我的应用程序列表中使用。我已经为“DiceDictor”编写了XML代码,如下所示 <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="line"> <stroke android:width="1px" android:color="@color/divider_Color" /> </shape>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line">
<stroke
android:width="1px"
android:color="@color/divider_Color"
/>
</shape>
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编码非常陌生。知道我哪里出错了吗?必须将分隔符设置为listView,而不是可以在xml中使用的线性布局
<View
android:layout_width="fill_parent"
android:layout_height="1dp" android:Background="@android:color/darker_gray"/>
要在布局之后设置分隔符,请尝试使用shape=“rectangle”
而不是行
<shape
android:shape="rectangle">
<size android:height="1px" />
<solid android:color="@color/white" />
</shape>
在res/drawable中创建一个文件mydivider.xml,并设置以下形状:
<?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>
添加形状作为布局的分隔符
<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>
没有列表视图。只有直线布局。据我所知,当我编写这段代码时,ListView不会执行我在这里想要执行的操作。此LinearLayout包含一系列其他LinearLayout,其中包含代码所需的所有有用小部件等。当我在ListView上查找信息时,它只能包含一个没有子视图的其他视图。存在用于线性布局的分割器方法。如果它们不工作,为什么它们会在那里呢?这是我在经历了很多混乱之后得到的解决方案(尽管我用Java代码创建了视图,因为我需要动态添加它们)。可惜的是,实际的android代码无法工作。它会更加优雅。为什么不通过代码动态添加这个视图呢?创建线性布局,然后在该线性布局之后添加此视图。这不是一个适合您的解决方案吗?请参阅代码示例[here][1],其中我还支持旧设备。[1] :别忘了android:showDividers
项!