title: Setting width of LinearLayout dynamically?
body: <p>I want to make my own custom "progress bar". I do this by drawing to linear layouts, each with a different color. After that I want to assign a width to each of them to make it look as a progress bar. The thing I am having right now:</p>
  
  <p>XML file of an item of my CustomAdapter (in Gridview):</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:background="#33c2bd" &gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:id="@+id/lineScore"
          android:layout_width="20dp"
          android:layout_height="2dp"
          android:background="#eef05e" 
          android:paddingLeft="20dp"
          android:paddingTop="0dp"
          android:paddingBottom="20dp"
          android:layout_below="@+id/tvLevelScore"/&gt;
  
      &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:id="@+id/lineScoreTotal"
          android:layout_width="20dp"
          android:layout_height="2dp"
          android:background="#0d7975" 
          android:paddingRight="20dp"
          android:paddingTop="0dp"
          android:paddingBottom="20dp"
          android:layout_below="@+id/tvLevelScore"
          android:layout_toRightOf="@+id/lineScore"/&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>Then in the CustomAdapter class under the getView method I am trying to set the lineScoreTotal to 80% of the width of the item:</p>
  
  <pre><code>double viewWidth = (double) mView.getWidth();
              int widthScoreBar = (int) (viewWidth * 0.8);
              LinearLayout ln = (LinearLayout) mView.findViewById(R.id.lineScoreTotal);
              ln.layout(0, 2, widthScoreBar, -1);
  </code></pre>
  
  <p>However, it is doing nothing... Am I applying the wrong code to set the width? Or is my idea of using LinearLayout to draw those "bars" maybe the wrong thing to do? </p>
  
  <p>EDIT getView method:</p>
  
  <pre><code>@Override
      public View getView(int position, View v, ViewGroup parent) {
          View mView = v;
  
          if (mView == null) {
  
              LayoutInflater vi = (LayoutInflater) getContext().getSystemService(
                      Context.LAYOUT_INFLATER_SERVICE);
              mView = vi.inflate(R.layout.levelselector_item, null);
  
          }
  
          TextView level = (TextView) mView.findViewById(R.id.tvLevel);
          TextView levelScore = (TextView) mView.findViewById(R.id.tvLevelScore);
  
          if (mView != null) {
  
              level.setText(Integer.toString(getItem(position).getLevel()));
  
              loadDataBase();
              int correctAnswers = myDbHelper.getCorrectAnswers(getItem(position).getLevel());
              correctAnswersPrev = 0;
              correctAnswersPrev = myDbHelper.getCorrectAnswersPrev(getItem(position).getLevel());
  
              String correct = Integer.toString(correctAnswers);
  
              levelScore.setText(correct + "/60");
              level.setTypeface(font);
              levelScore.setTypeface(font);
  
              LinearLayout ln = (LinearLayout) mView.findViewById(R.id.lineScoreTotal);
              ln.setLayoutParams(new FrameLayout.LayoutParams(10, 10));
  }
          return mView;
      }
  </code></pre>