0

I have a problem that when I set a layout xml file on an activity with width & height = fill_parent and set a background color as, say, grey, i do not get any background color when I start the activity. I tried creating a custom layout which extends LinearLayout and when I call onMeasure at this custom layout, i get

onMeasure: -2147483048 | -2147482761

where horizontal space requirements : -2147483048 and vertical space requirements : -2147482761

So, when I use

setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
                LayoutParams.FILL_PARENT));

for my custom layout, i get nothing, but when i use for example

setLayoutParams(new LayoutParams(50,
            50));

then i get a rectangle

My question is, why?

EDIT: Tested on real phones and emulators

EDIT2: xml:

android:layout_width="fill_parent"
android:layout_height="fill_parent"

EDIT3: java:

onCreate:
        setContentView(new CustomAlarmLayout(this));

or

onCreate:
setContentView(R.layout.some_layout);

EDIT4: The number is equal MeasureSpec.AT_MOST

trying to set it to MeasureSpec.UNSPECIFIED doesn't change anything, the view is still not resized when onMeasure is called

EDIT5: My bad. The problem was that there was a wrap_content set on the TabWidget common area, so that is why my fill_parent wouldn't work

Kev
  • 118,037
  • 53
  • 300
  • 385
Boris Mocialov
  • 3,439
  • 2
  • 28
  • 55
  • Add xml please. Btw use match_parent, as fill_parent is deprecated as of API level 8 – stealthjong Sep 25 '12 at 10:32
  • 1
    What is going on about the downvotes??? this is a valid question, and I am tired of seeing downvotes everywhere just because some smart ass doesn't like the way a question is being asked or anything else... this is a great community with some really stupid members sometimes.. – Sebastian Breit Sep 25 '12 at 10:40
  • @Perroloco there are rules about how you ask a question) – Boris Mocialov Sep 25 '12 at 10:52
  • Please post onCreate() method and xml please. And with xml I don't mean a single line of xml with a correct syntax. How are we supposed to help if you only give single lines of code? – stealthjong Sep 25 '12 at 11:27
  • because that is all i've got except for the default parts of application – Boris Mocialov Sep 25 '12 at 11:30

2 Answers2

0

Are you sure?? You must be doing something wrong either in your layout xml or your activity.

Try using the following 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="horizontal" 
    android:background="#FF0000">
</LinearLayout>

You should get a red background

Sebastian Breit
  • 6,137
  • 1
  • 35
  • 53
0

I understand that you want insert this layout (and its setting) in runcode...why you don´t try include in the .xml file of this activity a relative or linear layout setting by default the params widht and height as a MATCH_PARENT or FILL_PARENT. After this, insert your linearlayout by runcode inside of that layout inn the .xml.

Something like that:

myGenericLayout = (LinearLayout) findViewById(R.id.layout);
myGenericLayout.addView ( "your layout with the setting that you want here" );
Juan Pedro Martinez
  • 1,924
  • 1
  • 15
  • 24