Issue
I am trying to create a dialog window in Android where I am dynamically creating the layout and adding the views in to it. But I want to add my view to a specific position in layout.
Here is my code snippet
final Dialog dialog = new Dialog(this);
FrameLayout fl=new FrameLayout(this);
TextView et = new TextView(this);
et.setText("asdas");
fl.addView(et,100,1200);
ColorDrawable cd=new ColorDrawable(android.graphics.Color.TRANSPARENT);
dialog.getWindow().setBackgroundDrawable(cd);
dialog.setContentView(fl);
Solution
I used this to place a image button at a specified location in my relative layout. hope this helps:
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
layoutParams.leftMargin = (int)(marginLeft);
layoutParams.topMargin = (int)(marginTop);
imageButton.setLayoutParams(layoutParams);
EDIT:
You can do this for other layouts that support positioning of child views. This method works even for lower API versions. Atleast it worked on API 10. :)
Answered By - Ankit Popli
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.