[英]How do I setup a custom ListView with divider using Android?
I wanted to implement Pull to Refresh feature in my android application, so I implemented this library: Android-PullToRefresh . 我想在我的android应用程序中实现Pull to Refresh功能,所以我实现了这个库: Android-PullToRefresh 。 However, I can't seem to set custom style to divide programmatically.
但是,我似乎无法设置自定义样式以编程方式划分。
The code is simple: 代码很简单:
list = (PullToRefreshListView) findViewById(R.id.list);
int[] colors = {0, 0xFF97CF4D, 0};
list.setDivider(new GradientDrawable(Orientation.RIGHT_LEFT, colors));
list.setDividerHeight(1);
However, it is throwing this error: The method setDivider(GradientDrawable) is undefined for the type PullToRefreshListView
and The method setDividerHeight(int) is undefined for the type PullToRefreshListView.
但是,它抛出了这个错误:
The method setDivider(GradientDrawable) is undefined for the type PullToRefreshListView
和The method setDividerHeight(int) is undefined for the type PullToRefreshListView.
What am I doing wrong here? 我在这做错了什么?
PullToRefreshListView
is not a ListView
, hence that error. PullToRefreshListView
不是ListView
,因此该错误。 You should access the ListView
inside PullToRefreshListView
and invoke setDivider*
methods on that. 您应该访问
PullToRefreshListView
的ListView
并在其上调用setDivider*
方法。
list = (PullToRefreshListView) findViewById(R.id.list);
int[] colors = {0, 0xFF97CF4D, 0};
ListView inner = list.getRefreshableView();
inner.setDivider(new GradientDrawable(Orientation.RIGHT_LEFT, colors));
inner.setDividerHeight(1);
As an alternative you could define your gradient as an XML drawable and set the attributes right in your layout like shown in the sample here 作为替代,你可以定义渐变为一个XML绘制,并在布局权设定的属性,如显示的示例中这里
eg: 例如:
<com.handmark.pulltorefresh.library.PullToRefreshListView
android:divider="@drawable/fancy_gradient"
android:dividerHeight="@dimen/divider_height"...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.