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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:37:32+00:00 2026-06-13T14:37:32+00:00

I have a custom view that I’m trying to use in a vertical orientation

  • 0

I have a custom view that I’m trying to use in a vertical orientation with a textview/button combo (stuck in a horizontal LinearLayout) positioned below it on the screen. Currently my layout looks like this:

    <com.company.widgets.MyCustomView
        android:id="@+id/custom"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" 
        android:layout_alignParentTop="true"
        android:layout_weight="0.0" />

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal|center_vertical"
        android:layout_marginTop="10dp"
        android:layout_alignParentBottom="true"
        android:layout_weight="1.0"
        android:orientation="horizontal" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical|left"
            android:layout_marginLeft="15dp"
            android:layout_marginRight="5dp"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:textColor="#000000"
            android:text="foobar" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical|right"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="15dp"
            android:text="foobar" />
    </LinearLayout>

In my custom view I’ve overridden onMeasure() and onSizeChanged(). I take pains to ensure that my view’s size doesn’t exceed the measureSpec (for onMeasure) or the width/height values (for onSizeChanged) that it is passed. However, when my activity is laid out, the values passed to these two methods represent “the whole vertical height of the screen”.

Consequently my custom view ends up making itself as tall as it wants to be and the button/textview make themselves “as tall as they need to be” (wrap_content). When these two heights exceed the height of the screen, the bottom portion of the custom view is drawn behind the button/textview.

My question: how should I modify the layout so that my custom view’s onMeasure() and/or onSizeChanged() methods are passed a shorter height value? I’d like them to receive a value representing “screen height – height of the textview/button”.

Note: if I change the layout so that the textview/button are positioned above the custom view, the height value I’m passed is correct (i.e. smaller than screen height).

  • 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-13T14:37:33+00:00Added an answer on June 13, 2026 at 2:37 pm

    Solved it. Make the outer element be a LinearLayout instead of Relative and reverse the weights. The custom view should have weight “1” and the LinearLayout that contains the TextView and Button should have weight zero. This causes the height value passed to my custom view’s onMeasure() to be only the portion of the screen not taken up by the textview/button.

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

Sidebar

Related Questions

I have a custom view that extends LinearLayout, with these constructors: public class CustomView
I have a custom view that I am trying to display, however I am
I have a custom View class that extends Spinner. I'm trying to figure out
I have a custom view that extends LinearLayout. I have implemented onSaveInstanceState() and onRestoreInstanceState()
I have a custom table view cell view that contains a button. I initialize
I have a custom View that I would like to embed in an WebView.
I have a custom view that accepts drags. In the custom view there is
I'm using Drupal 6. I have a custom view that needs to be filtered
I have a custom control/view that observes the direction of a gesture within its
I have a custom-made view that extends the View class. I would like 2

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.