Adding layout properties dynamically
<p>I have added a <code>LinearLayout</code> dynamically and a <code>TextView</code> into it. Now I have to add the background, format them as per my requirement. So I am stuck with few questions. Here is my code:</p>

<pre><code>LinearLayout parentLayout = (LinearLayout) findViewById(R.id.master);
LinearLayout Linear1 = new LinearLayout(this);
Linear1.setOrientation(LinearLayout.HORIZONTAL);
Linear1.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
        LayoutParams.MATCH_PARENT));
Linear1.setId(1);
TextView tvLeft = new TextView(this);
tvLeft.setText("Hello");
tvLeft.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
        LayoutParams.WRAP_CONTENT));
Linear1.addView(tvLeft);
parentLayout.addView(Linear1);
</code></pre>

<p>I have few questions:</p>

<ul>
<li>How can I add drawable resource as my background?</li>
</ul>

<p>I have tried this:</p>

<pre><code>Linear1.setBackgroundResource(getResources().getDrawable(R.drawable.gradient_pink));
</code></pre>

<p>I am getting error message by the compiler as: </p>

<blockquote>
  <p>The method setBackgroundResource(int) in the type View is not applicable for the arguments (Drawable)</p>
</blockquote>

<ul>
<li>How to access the element whose id is set pragmatically?</li>
<li>How to set width = 0dip?</li>
</ul>

<p>Please help me with these question.</p>
