Skip to content Skip to sidebar Skip to footer

Making A Layout Big As The Real Content, Not The Background

I have a relativeLayout with two children: two textviews, one below the other. The relativeLayout has wrap_content as the height rule. Now this relative_layout has a background tha

Solution 1:

Ok, here's one approach:

TextViewCounterMechanicsTitle= (TextView) findViewById(R.id.CounterMechanicsTitle);
    TextViewCounterMechanics= (TextView) findViewById(R.id.CounterMechanics);
    Drawabledr= getResources().getDrawable(R.drawable.counter_background2);
    RelativeLayoutrl= (RelativeLayout) findViewById(R.id.mid);

    intheightOfTextViews= CounterMechanicsTitle.getHeight() + CounterMechanics.getHeight();
    //Now you have the height of the two TextViewsBitmapbitmap= ((BitmapDrawable) dr).getBitmap();
    // Scale the drawable to heightOfTextViews *1.6 x heightOfTextViews, so to be scaled properlyDrawabled=newBitmapDrawable(getResources(), Bitmap.createScaledBitmap(bitmap, heightOfTextViews*1.6, heightOfTextViews, true));

rl.setBackground(d);
    //Optional //rl.getLayoutParams().height = heightOfTextViews;//rl.getLayoutParams().width = heightOfTextViews*1.6;

See if this fixes it.

Post a Comment for "Making A Layout Big As The Real Content, Not The Background"