How can I place a div line programmatically using java? The XML code is:
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#ddd" />
How can I place a div line programmatically using java? The XML code is:
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#ddd" />
For example, to insert into a LinearLayout
, you first need to instantiate it:
LinearLayout linear = (LinearLayout)findViewById(R.id.linearLayout);
Then just create a View
programmatically in this way, using the setLayoutParams
method to set the width settings View
:
View divider = new View(this);
divider.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, 1));
divider.setBackgroundColor(Color.rgb(51, 51, 51));
linear.addView(divider);
You can also set a color using a static color from the Color class . See:
linear.setBackgroundColor(Color.RED);