Android 如何在TextView中设置行分隔线
我想在Android 如何在TextView中设置行分隔线,android,Android,我想在TextView中的每一行之间有一行。 原始TextView可以这样做吗? 如果没有,我怎么做 答复: 感谢@Slartibartfast的参考和建议。我制作了一个定制的TextView。我得到了这样的东西 这就是我想要的 守则: public class LinedTextView extends TextView { private Rect mRect; private Paint mPaint; public LinedTextView(Context context)
TextView
中的每一行之间有一行。
原始TextView
可以这样做吗?
如果没有,我怎么做
答复: 感谢@Slartibartfast的参考和建议。我制作了一个定制的
TextView
。我得到了这样的东西
这就是我想要的
守则:
public class LinedTextView extends TextView {
private Rect mRect;
private Paint mPaint;
public LinedTextView(Context context) {
super(context);
initialize();
}
public LinedTextView(Context context, AttributeSet attrs) {
super(context, attrs);
initialize();
}
public LinedTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
initialize();
}
private void initialize() {
mRect = new Rect();
mPaint = new Paint();
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setColor(0x800000ff);
}
@Override
protected void onDraw(Canvas canvas) {
int cnt = getLineCount();
Rect r = mRect;
Paint paint = mPaint;
for (int i = 0; i < cnt; i++) {
int baseLine = getLineBounds(i, r);
canvas.drawLine(r.left, baseLine + 1, r.right, baseLine + 1, paint);
}
super.onDraw(canvas);
}
}
公共类LinedTextView扩展了TextView{
私人直肠;
私人油漆;
公共LinedTextView(上下文){
超级(上下文);
初始化();
}
公共LinedTextView(上下文、属性集属性){
超级(上下文,attrs);
初始化();
}
公共LinedTextView(上下文、属性集属性、int-defStyle){
超级(上下文、属性、定义样式);
初始化();
}
私有void初始化(){
mRect=新的Rect();
mPaint=新油漆();
mPaint.setStyle(油漆、样式、笔划);
mPaint.setColor(0x800000ff);
}
@凌驾
受保护的void onDraw(画布){
int cnt=getLineCount();
Rect r=mRect;
油漆油漆=mPaint;
对于(int i=0;i
使用文本视图下方的以下代码行
<View android:layout_width="fill_parent"
android:layout_height="1px"
android:background="@android:color/background_dark" />
您可以根据需要进行配置
您也可以使用带分隔符的ListView
。使用带分隔符的ListView。使用背景图像。您可以跟随并创建复杂的文本视图,或者执行简单的操作,如@Raghunandan所说,并使用列表视图。我想定制文本视图将是我的选择,而不是使用带分隔符的列表视图或TextView下面的视图。因为我会费劲地将单词分隔到ListView的每个项目中。谢谢@Slartibartfast的推荐,这才是我真正想要的!感谢@tgrll的评论。