Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/187.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android:文本视图中的规则/水平线_Android_Textview - Fatal编程技术网

Android:文本视图中的规则/水平线

Android:文本视图中的规则/水平线,android,textview,Android,Textview,在Android中,我有一个文本视图,它的内容将是动态的。我想在每行文本后显示一条水平线。我搜索了很多,找到了EditText()。我打算画动态文本视图,并在它们下面画一条水平线。但我不知道怎样才能检测到线路的尽头。我们将非常感谢您的帮助。我希望与所附的可以使用视图绘制直线:对于水平线: <View android:layout_height="1dp" android:layout_width="fill_parent" android:background="#ffffff" />

在Android中,我有一个文本视图,它的内容将是动态的。我想在每行文本后显示一条水平线。我搜索了很多,找到了EditText()。我打算画动态文本视图,并在它们下面画一条水平线。但我不知道怎样才能检测到线路的尽头。我们将非常感谢您的帮助。我希望与所附的


可以使用视图绘制直线:对于水平线:

<View
android:layout_height="1dp"
android:layout_width="fill_parent"
android:background="#ffffff" />

我正在使用在EditText中的每行文本之间画线的技术,然后通过将setKeyListener(null)设置为自定义EditText对象,使EditText不可编辑,这样,EditText就像一个TextView:)


在显示的每行文本之间绘制线条的自定义编辑文本:
et.setKeyListener(null)使EditText不可编辑,因此它的行为类似于TextView


输出:

光标问题: 如果您仅使用et.setKeyListener(null),则它只是不侦听键,而是 用户可以在编辑文本上看到光标。如果不需要此光标,只需通过添加以下行禁用EditText:

 et.setEnabled(false);

它会画水平线,因为我的文字不是固定的。我必须在每一条新线下添加水平线。但我不知道如何在不同的屏幕上跟踪每一条线。这太棒了!如何更改它,使整个控件都有行(即使没有文本)(对于固定大小的控件)?
public class LinedEditText extends EditText {
    private Rect mRect;
    private Paint mPaint;

    // we need this constructor for LayoutInflater
    public LinedEditText(Context context, AttributeSet attrs) {
        super(context, attrs);

        mRect = new Rect();
        mPaint = new Paint();
        mPaint.setStyle(Paint.Style.STROKE);
        mPaint.setColor(0x800000FF);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        int count = getLineCount();
        Rect r = mRect;
        Paint paint = mPaint;

        for (int i = 0; i < count; i++) {
            int baseline = getLineBounds(i, r);

            canvas.drawLine(r.left, baseline + 1, r.right, baseline + 1, paint);
        }

        super.onDraw(canvas);
    }
} 
public class HorizontalLine extends Activity{
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {   
        super.onCreate(savedInstanceState);
        setTitle("Android: Ruled/horizonal lines in Textview");

        LinearLayout ll = new LinearLayout(this);
        ll.setOrientation(LinearLayout.VERTICAL);
        LayoutParams textViewLayoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

        LinedEditText et = new LinedEditText(this, null);
        et.setText("The name of our country is Bangladesh. I am proud of my country :)");
        et.setLayoutParams(textViewLayoutParams);
        et.setKeyListener(null);

        ll.addView(et);
        this.setContentView(ll);

    }

}
 et.setEnabled(false);