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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:38:27+00:00 2026-06-03T03:38:27+00:00

I am playing around with background images of TextView objects in Android, and I

  • 0

I am playing around with background images of TextView objects in Android, and I am wondering about the strange behaviour with the height.

How come I can’t set the height of the TextView to 0 so it gets “invisible” and doesn’t use up any space anymore – when setting a background-image?

Here is some test-code that demonstrates the – for me – strange behaviour.

public class HelloAndroid extends Activity implements View.OnClickListener{

TextView btn;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    btn = new TextView(this);
    btn.setOnClickListener(this);
    //Put in any drawable of you in here
    btn.setBackgroundDrawable(getResources().getDrawable(R.drawable.restablebg5));
    btn.setHeight(80);

    LinearLayout v = new LinearLayout(this);
    v.setOrientation(LinearLayout.VERTICAL);
    v.addView(btn);
    setContentView(v);        

}

public void onClick(View arg0) {
    btn.setHeight(0);

}

}

How can I set the height of the textview to 0?

Thanks

  • 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-03T03:38:29+00:00Added an answer on June 3, 2026 at 3:38 am

    Do this instead:

    btn.setVisibility(View.GONE);

    you can also use:
    btn.setVisibility(View.INVISIBLE);

    the second option will maintain the space, but your item won’t be visible – the first option completely removes your item from the display (and doesn’t maintain the space).

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

Sidebar

Related Questions

I come from a web-development background. I've been playing around with a bit of
Been playing around with this for a couple of hours and can't seem to
Was playing around a little bit with the TimeSpan class and I started wondering
I've been playing around with Android development and one of the things I'd like
Quick background I'm a Java developer who's been playing around with C++ in my
I was playing around with this script of auto scrolling text. You can check
I'm just learning c++ coming from a Java background. Just playing around with simple
I have long programming background, but am new to Python, and am playing around
I'm playing around with visual controls and colors in a simple background color changing
I've been playing around with Pyramid lately and, coming from a Pylons background, I've

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.