Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8832225
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:28:49+00:00 2026-06-14T08:28:49+00:00

I have sub classed a View to create a custom control. Below is my

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T08:28:50+00:00Added an answer on June 14, 2026 at 8:28 am

    I reccomend using a RelativeLayout:

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    
        <"com.rciicustomclass.MyAdvertisement"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true" />
    
    </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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Brief: I have a sub classed AuthorizeAttribute in my framework in which I am
I have several custom uibuttons on my view. I want to create a toggle
I have a custom view that I would like to create from a resource
I have a collection of Objective-C classes that get sub-classed at a variety of
I have a class Field of which there are two sub-classes AccountField and DecimalField
I have subclassed a control in C# WinForms, and am custom drawing text in
I have a web solution (in VS2010) with two sub-projects: Domain which holds the
In many application I often have algorithms which make use of dedicated sub-algorithms (or
I have a Header at the top of 3 lists, which contains simple Create
I have subclassed SimpleCursorAdapter in order to create a custom list entry layout containing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.