1
How can I program a dividing line using java? The XML code is:
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#ddd" />
1
How can I program a dividing line using java? The XML code is:
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#ddd" />
2
For example, to insert into a LinearLayout
, first need instance it:
LinearLayout linear = (LinearLayout)findViewById(R.id.linearLayout);
Then just create a View
programmatically this way below, using the method setLayoutParams
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);
It is also possible to define a color using a static color of color class. Behold:
linear.setBackgroundColor(Color.RED);
Thank you very much! Certíssimoooo
@Fabriciochavesjorhge The answer attracts you or needs some more information?!
Browser other questions tagged java android
You are not signed in. Login or sign up in order to post.
Do you want to insert this line where? For example, Listview, Menu, Recyclerview, Layout, etc.?! It is important to let this be detailed in the question, because perhaps, I say perhaps, for each case there is a different solution.
– viana
I want to insert the line into a layout. Its like inserting a Textview or an image. Now I want a dividing line between the text and the image.
– Fabricio Chaves Jorhge