How Can I Draw A Vertical Line In An Activity When A Button Is Pressed?
I want to draw a straight vertical line in my Android activity when a button is pressed. Please explain how I can draw the line with a position & length I want. Elaboration: I
Solution 1:
I have solved it myself. All you need to do is define a View with appropriate parameters and fill the background with color. You may want to use nested linear layouts for positioning the line correctly.
<View
android:id="@+id/View01"
android:layout_width="2dip"
android:layout_height="500dip"
android:background="#2B497B"
/>
So if it may be useful to anyone else, I have posted the answer here myself!
Solution 2:
To draw dynamically u can use below code snippet:
Viewview=newView(this);
view.setLayoutParams(new LayoutParams(2,LayoutParams.FILL_PARENT));
view.setBackgroundColor(Color.BLACK);
layout.add(view);
Solution 3:
The linear layout mentioned can be used as a divider by itself
<LinearLayoutandroid:layout_width="fill_parent"android:layout_height="3dp"android:layout_marginTop="152dp"android:background="@color/black"android:orientation="horizontal"
/>
I did this as my screen required a horizontal seperator dividing the screen into two halves..
Post a Comment for "How Can I Draw A Vertical Line In An Activity When A Button Is Pressed?"