title: BackgroundColor in LinearLayout of the width of the screen
body: <p>I created a gallery with horizontalscrollview. In the imageview LinearLayout I've put a color background. I want the LinearLayout spans the width of the screen with or without images. How I can do?</p>
  
  <pre><code>&lt;LinearLayout 
      android:id="@+id/linear1"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:paddingBottom="5dp"
      android:orientation="vertical"&gt;
  
      &lt;HorizontalScrollView
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:scrollbars="none"&gt;
  
          &lt;LinearLayout
                  android:id="@+id/linear2"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:orientation="horizontal"
                  android:background="@color/estandar"
                  android:padding="2dp"
            /&gt;
      &lt;/HorizontalScrollView&gt;
   &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>main.xml</p>
  
  <pre><code>            LinearLayout linear2 = (LinearLayout) findViewById(R.id.linear2);
  
              LayoutParams params = linear2 .getLayoutParams();
              params.height = 100;
              params.width = 300;
  </code></pre>
  
  <p>but my code does not work.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <pre><code>    DisplayMetrics metrics = new DisplayMetrics();
      getWindowManager().getDefaultDisplay().getMetrics(metrics);
      int anchoPantalla = metrics.widthPixels;
  
          if (listaImagenes.length &gt; 0) {
  
              for (String nombreImagen : listaImagenes) {
  
                  InputStream is = getAssets().open(directorioImagenes + "/" + nombreImagen);
                  final Bitmap bitmap = BitmapFactory.decodeStream(is);
  
                  final ImageView imageView = new ImageView(getApplicationContext());
  
                  alto = bitmap.getHeight();
                  ancho = bitmap.getWidth();
  
                  final float calculo = ancho / (alto / ALTO_IMAGEN);
  
              imageView.setLayoutParams(new ViewGroup.LayoutParams((int)calculo, ALTO_IMAGEN));
  
                  imageView.setImageBitmap(bitmap);
                  imageView.setPadding(2, 2, 2, 2);
                  imageView.setBackgroundColor(colorResources);
  
                  imageView.setOnClickListener(new View.OnClickListener() {
                      public void onClick(View view) {
  
                              ...
                      }
                  });
  
                  linear2.addView(imageView);
              }
  
          } else {
  
              // PAINT LINE WIDTHSCREEN x 120dp 
          }
  </code></pre>