Dim
Dim

Reputation: 4807

Adding custom view to relative layout

I am adding image dynamically to relative layout like that:

RelativeLayout relUsers= (RelativeLayout) findViewById(R.id.RelativeLayoutUsers);

            lpIm = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT);
            lpIm.leftMargin = x;
            lpIm.topMargin = y;

            ImageView imageView = new ImageView(this);
            imageView.setImageResource(R.drawable.dot_red);

            relUsers.addView(imageView, lpIm);

But I need that under the image will be some text view so I can change. Do I need to create custom class that extends liner layout (or relative)? Ho do I create that custom class or view?

Upvotes: 0

Views: 378

Answers (1)

noni
noni

Reputation: 2947

You can create a TextView instance and then set the property "layout_below" to it. Remember to set an ID to the ImageView, because if you don't do that, layout_below will be useless, it works with the ID of the view.

lpIm.addRule(RelativeLayout.BELOW, R.id.image_view)

You have to set the same ID to the ImageView, otherwise it wont work. Thanks for the comment, copy pasted it

Upvotes: 1

Related Questions