Note that there are some explanatory texts on larger screens.

plurals
  1. POAdding multiple framelayout in a linearlayout programmatically
    primarykey
    data
    text
    <p>I need to overlap an image view with textview. And this combined view will be repeated 100 times in a LinearLayout. I was thinking of using FrameLayout in LinearLayout and Repeating the FrameLayout in LinearLayout 100 times when FrameLayout holds the imageview and textview overlapped. Need to do this programatically not from xml file. </p> <p>I added the image and textview to framelayout first then tried to add the framelayout to linearlayout. But it says : the specified child has already a parent.. so not working. Can you please show me in code? Thanks for your help.</p> <p>it is going to be like this, but need to be done programmaticaly</p> <pre><code>---linear layout-------------- ------------------------------ |frame layout----------------| ||txt view on top of img view| ------------------------------ frame layout will be repeated| ---/end of linear layout------ </code></pre> <p>Also here is the separated code:</p> <pre><code>public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_test); LinearLayout dynamicview = (LinearLayout) findViewById(R.id.main_layout); FrameLayout barFrameLayout = new FrameLayout(this); FrameLayout.LayoutParams params = new FrameLayout.LayoutParams( LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, Gravity.CENTER); barFrameLayout.setLayoutParams(params); LinearLayout.LayoutParams slparams1 = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); for (int i = 65; i &lt;= 75; i++) { TextView catTV = new TextView(this); catTV.setLayoutParams(slparams1); catTV.setText("===" + Character.toString((char) i) + "==="); catTV.setTextSize(32); ImageView iv = new ImageView(this); iv.setImageResource(R.drawable.ic_launcher); iv.setLayoutParams(slparams1); barFrameLayout.addView(catTV); barFrameLayout.addView(iv); dynamicview.addView(barFrameLayout); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload