i need to create a white separator line with java. I need to add it into my relativelayout, but allways with java, because i am learning to use relativelayout with java.
I know how to create the line with xml:
<View
android:layout_gravity="center_horizontal"
android:layout_width="fill_parent"
android:layout_height="1dip"
android:background="#808080"
android:layout_marginTop="5px"/>
But now i need to add it into my relative layout with java code:
RelativeLayout rl= new RelativeLayout(this); //Contiene el menu superior con sus botones.
home= new ImageView(this);
home.setImageResource(R.drawable.but_home_up);
rl.addView(home);
homeParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
homeParams.setMargins(10, 0, 0, 0);
home.setId(5);
home.setLayoutParams(homeParams);
I want to put the separator line below the Home imageView.
How can i do it?
I tryed with this code, but it doesn’t work… it is painting a VERTICAL LINE, and i want HORIZONTAL:
View line = new View(this);
RelativeLayout.LayoutParams lineParams = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
lineParams.setMargins(0,0,10,0);
lineParams.addRule(RelativeLayout.BELOW,5);
lineParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
lineParams.width=1;
line.setId(6);
line.setBackgroundColor(0xFF808080);
line.setLayoutParams(lineParams);
rl.addView(line);
thanks
Replace in your last code example
lineParams.width = 1;tolineParams.height = 1;. It should work.