Add a Textview to a FrameLayout in a determined position

后端 未结 6 1829
旧巷少年郎
旧巷少年郎 2021-01-12 09:18

I\'m trying to add a textView to a frameLayout. The TextView has wrap_content properties, so it grows when the text grows

6条回答
  •  情深已故
    2021-01-12 09:50

    Try this:

    FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, Gravity.CENTER);
    
    ((FrameLayout) findViewById(R.id.mainLayout)).addView(mEditText, params);
    

    Change Gravity to suit your need.

    BTW, the frame layout should use fill_parent for width and height

提交回复
热议问题