How can I draw a vertical line in an Activity when a button is pressed?

99封情书 提交于 2019-12-02 19:39:44
kiki

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!

Lakshmanan

To draw dynamically u can use below code snippet:

 View view = new View(this);
 view.setLayoutParams(new LayoutParams(2,LayoutParams.FILL_PARENT));
 view.setBackgroundColor(Color.BLACK);
 layout.add(view);

The linear layout mentioned can be used as a divider by itself

<LinearLayout 
        android: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..

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!