1

I'm trying to dynamically put a bitmap in between a Textview and a Button:

<TextView android:text="TextView" android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
<LinearLayout android:layout_height="wrap_content" android:id="@+id/linearLayout1" android:layout_width="wrap_content" android:orientation="vertical">
</LinearLayout>
<LinearLayout android:layout_width="fill_parent" android:id="@+id/linearLayout2" android:layout_height="fill_parent" android:orientation="vertical">
    <Button android:layout_width="fill_parent" android:layout_gravity="fill_vertical" android:text="Button" android:layout_height="fill_parent" android:id="@+id/button1">    </Button>
</LinearLayout>

In my Main Activity I create my custom view and add it to the LinearLayout1

mView = new myView(this);
LinearLayout ll = (LinearLayout)findViewById(R.id.linearLayout1);
ll.addView(rView);

My problem is, that myView consumes all available space below of it.

What am I missing?

Thnx in advance.

1
  • try adding layout parms for the view. Commented Nov 2, 2011 at 12:27

2 Answers 2

2

Try to set layout Parameter dynamically for your custom View.

l1.addView(rView, new LinearLayout.LayoutParams(100, LayoutParams.WRAP_CONTENT));

similarly try to set left and right position dynamically

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much! This was the solution I searched 7h!
1

You should add the LayoutParams when adding the view:

ll.addView(rView, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

In case you want to add it to a specific position you should use: addView(child, index).

Hope this helps!

1 Comment

Hi Dimitris, I just checked your solution, but my problem remains. As i needed my view (which contains a square bitmap) on width*width size the following code gave me the correct picture: ll.addView(rView, new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, ((WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getWidth()));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.