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 6712511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:16:05+00:00 2026-05-26T08:16:05+00:00

I have this xml : <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:orientation=vertical android:layout_width=fill_parent android:layout_height=fill_parent android:background=@drawable/photo0 android:id=@+id/imagBackground> <TextView android:layout_width=20dip

  • 0

I have this xml :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:background="@drawable/photo0"
    android:id="@+id/imagBackground">

    <TextView android:layout_width="20dip" android:layout_height="20dip"
        android:layout_marginLeft="250dip" android:layout_marginTop="15dip" android:background="#FFFFFF"
        android:id="@+id/index" android:text="0" android:textColor="#000000">
        </TextView>

        <ImageView android:layout_marginTop="280dip"
            android:layout_width="fill_parent" android:layout_height="wrap_content"
            android:background="@drawable/anim_ctrl_panel" android:id="@+id/change">
        </ImageView>
</LinearLayout>

and over this I must draw some rectangular by code. How to do this ?

I tried this :

@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        layout = (LinearLayout) findViewById(R.id.imagBackground);
        changeImage = (ImageView) findViewById(R.id.change);
        index = (TextView) findViewById(R.id.index);

        draw();
    }

        private void draw() {
        System.out.println("desenam");
        int width = 50;
        int height = 100;

        Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);

        Paint paint = new Paint();
        paint.setColor(Color.BLUE);


        Canvas canvas = new Canvas(bitmap);

        canvas.drawColor(Color.RED);

        canvas.drawRect(25, 50, 75, 150, paint);
         ImageView imageView = new ImageView(this);


        imageView.setImageBitmap(bitmap);

         layout.addView(imageView);

        setContentView(layout);
    }

but the rectangulars are on the bottom on screen. How to set the location where to put them?

  • 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-05-26T08:16:06+00:00Added an answer on May 26, 2026 at 8:16 am

    My guess is, the reason why it’s in the bottom of the page is because of the LinearLayout: in the end you will have 3 children: TextView, ImageView and ImageView, all below each other.

    A few possible solutions:

    1. Add a FrameLayout inside the LinearLayout and add the ImageViews inside it, so the hierarchy would be:

      • LinearLayout
        • TextView
        • FrameLayout
          • ImageView
          • ImageView
    2. Use a RelativeLayout instead of the LinearLayout and align all the edges of the second ImageView with the first one

    3. Create a custom ImageView class, for example “com.foo.bar.MyImageView”, which of course extends ImageView. Override onDraw:

      public void onDraw(Canvas canvas) {
          super.onDraw(canvas); // This will render the original image
          // ... and here you can have the code to render the rectangle
      }
      

    In the xml you replace

     <ImageView ...
    

    with

     <com.foo.bar.MyImageView ...
    

    I would go for the last solution, since from a performance point of view it’s the best.

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

Sidebar

Related Questions

This is my XML with 2 LinearLayouts . <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:layout_width=fill_parent android:layout_height=fill_parent> <LinearLayout android:id=@+id/ll_one
I have this code: <?xml version=1.0 encoding=utf-8?> <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:id=@+id/layoutAnim android:orientation=horizontal android:layout_width=fill_parent android:layout_height=fill_parent> <LinearLayout
I have this XML: <?xml version=1.0 encoding=utf-8?> <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android xmlns:ads=http://schemas.android.com/apk/lib/com.google.ads android:id=@+id/LinearLayout1 android:layout_width=fill_parent android:layout_height=fill_parent android:background=@drawable/fondoverde3
I have an Activity that calls setContentView with this XML: <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:layout_width=fill_parent android:layout_height=fill_parent
I have this simple layout: <?xml version=1.0 encoding=utf-8?> <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:layout_width=fill_parent android:layout_height=fill_parent android:orientation=vertical >
I have this xml-file: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#444548"> <ImageView android:layout_width="wrap_content"
I have a linear layout with this form <?xml version=1.0 encoding=utf-8?> <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:orientation=vertical
So my main.xml looks like this: <?xml version=1.0 encoding=utf-8?> <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:layout_width=fill_parent android:layout_height=fill_parent android:orientation=vertical
i have a custom adapter for an arraylist. <?xml version=1.0 encoding=utf-8?> <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:layout_width=wrap_content
I have a main activity with this layout file: <?xml version=1.0 encoding=utf-8?> <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android

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.