Alex Bond Alex Bond - 29 days ago 11
Android Question

Programmatically draw line under TextView

I have a layout that adds

TextView
's in loop dynamically:

TextView msg = new TextView(this);
TextView Bmsg = new TextView(this);
msg.setText(splittedItem[0]);
msg.setTextColor(0xFF2C85A6);
msg.setTextSize(22);
msg.setPadding(10, 10, 0, 10);
Bmsg.setText("- "+splittedItem[1]);
Bmsg.setPadding(20, 0, 10, 30);
Bmsg.setTextSize(18);
linearLayout.addView(msg);
linearLayout.addView(Bmsg);


And I want to divide each
TextView
with a line like this:



I need a line under
Bmsg
. I have found this - draw line under TextView on Android, but I do not understand how to make this programmatically.

in XML:

<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/buttonlayout">
</LinearLayout>

Answer

use this and let me know if it works

View view = new View(this);
view.setLayoutParams(new LinearLayout.LayoutParams(
    LayoutParams.MATCH_PARENT,2
));
view.setBackgroundColor(Color.parseColor("#000000"));

linearlayout.addView(view);