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

  • SEARCH
  • Home
  • 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 1114307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:59:15+00:00 2026-05-17T02:59:15+00:00

can we set the width of a view in android?

  • 0

can we set the width of a view in android?

  • 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-17T02:59:16+00:00Added an answer on May 17, 2026 at 2:59 am

    Actually I am placing an image as background in a view.
    I want to clip that image and the clipped image should fill the entire view.
    I am not getting it right.can you help.
    here is my code….

    try{
    setContentView(R.layout.main);
    ImageView img = (ImageView)findViewById(R.id.img);

            Paint paint = new Paint();
            paint.setFilterBitmap(true);        
            Bitmap bitmapOrg = BitmapFactory.decodeResource(getResources(),R.drawable.puli);
    
            int targetWidth  = 300;
            int targetHeight = 300;
    
    
            Bitmap targetBitmap = Bitmap.createBitmap(targetWidth, targetHeight,Bitmap.Config.ARGB_8888);
    
           // System.out.println(" P  ointsArrayX =" + PointsArrayX[i-1] + " PointsArrayY =" + PointsArrayY[i-1]);
    
            RectF rectf = new RectF(0, 00, 100, 100);
    
            Canvas canvas = new Canvas(targetBitmap);
            Path path = new Path();               
    
            path.addRect(rectf, Path.Direction.CW);
            canvas.clipPath(path);
    
            canvas.drawBitmap( bitmapOrg,new Rect(0, 0, bitmapOrg.getWidth(), bitmapOrg.getHeight()),
                            new Rect(0, 0, targetWidth, targetHeight), null);
    

    // Matrix matrix = new Matrix();
    // // resize the bit map
    // matrix.postScale(100, 133);
    //
    // Bitmap resizedBitmap = Bitmap.createBitmap(targetBitmap, 0, 0, 100, 133, matrix, true);
    // //
    /*convert Bitmap to resource */
    BitmapDrawable bd = new BitmapDrawable(targetBitmap);

            AbsoluteLayout.LayoutParams abs_params = 
                new AbsoluteLayout.LayoutParams(
                    //width in pixels
                    30,
                    //height in pixels
                    40, 0, 0
                );
    
            img.setLayoutParams(abs_params);
            img.setImageDrawable(bd);
    
    
        img.setOnTouchListener(new OnTouchListener() {
    
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                System.out.println("onTouch");
                return false;
            }
        });
    
        }
        catch(Exception e){
            System.out.println("Error1 : " + e.getMessage() + e.toString());
      }
    

    //my main.xml is

    android:layout_height=”300dp”
    android:layout_width=”300dp”
    android:id=”@+id/img”
    android:layout_x=”10dip”
    android:layout_y=”50dip”

    the problem is that the image is clipped and placed in the view but the clipped portion is still there. I was not able to resize the image to fit that view.Help me to solve this.Thankyou.

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

Sidebar

Related Questions

How can I set a fixed width for an Android button? Everytime I try
I can set the width and height of my canvas by setting the width
How can I set the width of an asp:chart to be 100% the width
How can the width of the textbox rendered by the @FileUpload helper be set?
I'm using the new ViewPager -view from the Android compatibility library, and I can't
Possible Duplicate: how to set shadow to a View in android? In my Android
Can i set setOnItemClickListener if i can't make list view.setonitemcliclistener because mi xml code
I am trying to get the width of a button whose android:layout_width is set
I can set appropriate layout for preference through android:layout attribute. For an example <Preference
I have a problem with grid view layout on Android. I can't find solution

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.