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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:20:10+00:00 2026-05-28T06:20:10+00:00

I have a tiled bitmap that I’m using as the View background. This View

  • 0

I have a tiled bitmap that I’m using as the View background. This View, let’s say, has android:layout_height="wrap_content". The problem is that the height of the bitmap used in the background is participating in the measurement of the view, increasing the View height. This can be noticed when the size of the content of View is smaller than the height of the bitmap used as the tile background.

Let me show you an example. The tile bitmap:

enter image description here

The bitmap drawable (tile_bg.xml):

<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
    android:src="@drawable/tile"
    android:tileMode="repeat"/>

The 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"
    android:background="#FFFFFF">

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/tile_bg"
        android:text="@string/hello"
        android:textColor="#000000" />

</LinearLayout>

How it looks like:

enter image description here

The height of the TextView ends up being the height of the bitmap. What I was expecting is that the bitmap gets clipped to the size of the View.

Is there any way to achieve this?

Notes:

  • I can’t use 9patch drawables since the background needs to be repeated in a tile fashion way, stretching is not an option.
  • I can’t set a fixed height for the View, it depends of the children (I’m using this in a ViewGroup)
  • This odd behavior happens as I explained before when the size of the View is smaller than the size of the bitmap, otherwise the bitmap is repeated an clipped correctly (ie, if the view size is 1.5x the size of the bitmap, you end up seeing 1.5 times the bitmap).
  • The example deals with the height, but is the same using the width.
  • 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-28T06:20:11+00:00Added an answer on May 28, 2026 at 6:20 am

    You need a custom BitmapDrawable that returns 0 from getMinimumHeight() and getMinimumWidth(). Here’s one I’ve named BitmapDrawableNoMinimumSize which does the job:

    import android.content.res.Resources;
    import android.graphics.drawable.BitmapDrawable;
    
    public class BitmapDrawableNoMinimumSize extends BitmapDrawable {
    
        public BitmapDrawableNoMinimumSize(Resources res, int resId) {
            super(res, ((BitmapDrawable)res.getDrawable(resId)).getBitmap());
        }
    
        @Override
        public int getMinimumHeight() {
            return 0;
        }
        @Override
        public int getMinimumWidth() {
             return 0;
        }
    }
    

    Of course you can’t (AFAIK) declare custom drawables in XML, so you have to instantiate and set the textview’s background thusly:

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    
        BitmapDrawable bmpd =new BitmapDrawableNoMinimumSize(getResources(), R.drawable.tile);
        bmpd.setTileModeX(TileMode.REPEAT);
        bmpd.setTileModeY(TileMode.REPEAT);
        findViewById(R.id.textView).setBackgroundDrawable(bmpd);
    }
    

    And of course you remove the background attribute from the layout xml:

    <TextView
        android:id="@+id/textView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Testing testing testing"
        android:textColor="#000000" />
    

    I’ve tested this and it seems to work.

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

Sidebar

Related Questions

Let's say we have a CCSprite object that has an actions tied to it:
I have a sticky footer which works, but I'm using a tiled background image
I have an NSCollectionView that contains a collection of CustomViews . Initially it tiled
I have a .NET webform that has a file upload control that is tied
Im developing a 2d RPG using surfaceview. This is how Ive done: I have
I'll explain my situation first: I'm interested of using the Bitmap constructor that takes
I have a bitmap that I have created by tiling the same graphic multiple
If I have a large bitmap file that would normally generate an Out of
I have a table of canvas elements that emulates tiled image. I need to
In my iPhone app I have a UIView with a tiled background image created

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.