I have sub classed a View to create a custom control. Below is my code in which I am trying to set the x, y, width and height.
But I am not able to set the x and y to position the view on the screen.
public class MyAdvertisement extends View{
public MyAdvertisement(){
super(null);
System.out.println("This first");
this.setBackgroundColor(android.graphics.Color.RED);
this.setMinimumWidth(500);
this.setMinimumHeight(100);
}
public MyAdvertisement(Context context){
super(context);
this.setBackgroundColor(android.graphics.Color.YELLOW);
this.setMinimumWidth(500);
this.setMinimumHeight(100);
}
public MyAdvertisement(Context context, AttributeSet attrs){
super(context, attrs);
this.setBackgroundColor(android.graphics.Color.YELLOW);
this.setMinimumWidth(500);
this.setMinimumHeight(50);
LayoutParams layoutParams=new LayoutParams(500,50);
layoutParams.setMargins(0, 400,0,0);
this.setLayoutParams(new LinearLayout.LayoutParams(layoutParams));
}
public MyAdvertisement(Context context, AttributeSet attrs, int defStyle){
super(context, attrs, defStyle);
this.setBackgroundColor(android.graphics.Color.GREEN);
this.setMinimumWidth(500);
this.setMinimumHeight(100);
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<view
class="com.rciicustomclass.MyAdvertisement"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/myb"
android:tag="tag"
/>
</LinearLayout>
I want to position the view at the bottom of the screen.
I reccomend using a RelativeLayout:
Plus there are plenty of other tags to position your View like centering, alignParentLeft, centerVertical, centerHorizontal, etc.
Also it is possible to place them relativeley to each other.