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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:26:35+00:00 2026-06-12T21:26:35+00:00

I have a LinearLayout (holder), which has match_parent for both width and height. In

  • 0

I have a LinearLayout (holder), which has match_parent for both width and height. In this holder I insert a View (a Class extending View). I do this inside the onCreate method of the Activity.

My question is, how do I make this child View stretch maximum horizontally and vertically, keeping a square shape, to fill as much area as possible from the parent LinearLayout?

Here’s what I use right now as a starting point:

    pieContainer = (LinearLayout) findViewById(R.id.pie_container_id);
    pie = new PieView(this);
    pieContainer.addView(pie);

I have tried playing around with overwriting the onMeasure method on both sides (the main activity and the PieView class), but to no avail.

  • 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-12T21:26:36+00:00Added an answer on June 12, 2026 at 9:26 pm

    Try this custom SquareView

    public class SquareView extends View {
      public SquareView(Context context) {
        super(context);
      }
    
      public SquareView(Context context, AttributeSet attrs) {
        super(context, attrs);
      }
    
      public SquareView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
      }
    
      public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        int size = Math.min(getMeasuredWidth(), getMeasuredHeight());
        setMeasuredDimension(size, size);
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just a straight forward problem. I have a LinearLayout which has attribute in xml
I have create a Java class extending LinearLayout as shown below public class CustomLinear
I have create a Java class extending LinearLayout as shown below public class News
I have a LinearLayout class in which I have: TexView | ImageView | EditText
I have LinearLayout inside of RelativeLayout. I would like to change height of LinearLayout
I have a LinearLayout, which only contains one button. I want this button to
I have LinearLayout inside TableRow. The LinearLayout get initiated in the code, this way:
I have a LinearLayout with a nested listview which looks like this: <LinearLayout ...
I have a LinearLayout set height as match_parent as below: <LinearLayout android:id=@+id/list_layout android:layout_width=match_parent android:layout_height=match_parent
I have a LinearLayout which holds a couple of buttons. To give the user

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.