tags:

views:

330

answers:

2

Hi guys.

Do you know how to draw line on the LinearLayout ?

To create a LinearLayout, I am using resource xml.

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_layout);
    LinearLayout linear = (LinearLayout)findViewById(R.id.linearlayout);
    //I wanna draw line on "linear"
}

Is it possible ?

Thanks in advance.

A: 

There are many ways; one way is to define a ShapeDrawable representing the line in XML (in your res folder) and set that as the background resource of say, an ImageView inside the LinearLayout.

You can read more about drawables and 2D graphics in general in the docs.

Feel free to provide some more context (specific use case) so I could elaborate on this answer or others could answer.

Roman Nurik
A: 

I created an image in an image editing tool that was a 2x2 pixel square of the color I wanted. Then in code I created an ImageView and set that image as the source. Lastly I set the ImageView height to FitContent and the width to FillParent and that gave me a horizontal line.

CaseyB