0

I have a LinearLayout where i placed many Views. When the Activity starts, i have an empty ImageView, that will be filled later with an image retrieved by remote. It's the XML of the Activity. Please look at the second View (first ImageView): as you can see, i want to set it's width to match_parent

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_raccolta"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" 
android:background="@drawable/bg_activity_main"
>


<TextView

    android:id="@+id/raccdetailtitle"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textSize="22sp"
    android:layout_marginBottom="20dp"
    android:text="Dettagli del Punto di Raccolta"
    android:textAlignment="center"
    android:gravity="center"




/>
<ImageView

    android:id="@+id/raccdetailimage"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="10dp"
    android:gravity="center"
    android:layout_gravity="center"
/>

<TextView

    android:id="@+id/raccdetailloc"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textSize="20sp"
    android:layout_marginBottom="10dp"
    android:textAlignment="center"
    android:gravity="center"

/>


    <TextView

    android:id="@+id/raccdetailloccity"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textSize="20sp"
    android:layout_marginBottom="5dp"
    android:textAlignment="center"
    android:gravity="center"

/>



<TextView

    android:id="@+id/raccdetailaddr"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textSize="18sp"
    android:layout_marginBottom="10dp"
    android:textAlignment="center"
    android:gravity="center"

/>

    <TextView

    android:id="@+id/raccdetailcontacts"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textSize="20sp"
    android:layout_marginBottom="10dp"
    android:text="Contatti"
    android:textAlignment="center"
    android:gravity="center"

/>

<TextView 
    android:id="@+id/callTextView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textSize="20sp"
    android:layout_marginBottom="20dp"
    android:textAlignment="center"
    android:gravity="center"
/>


<TextView 
    android:id="@+id/mailTextView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textSize="20sp"
    android:layout_marginBottom="20dp"
    android:textAlignment="center"
    android:gravity="center"
/>


<TextView 
    android:id="@+id/webTextView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textSize="20sp"
    android:layout_marginBottom="20dp"
    android:textAlignment="center"
    android:gravity="center"
/>

<TextView
    android:id="@+id/raccNote"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textSize="16sp"
    android:layout_marginBottom="20dp"
/>

After the Activity is loaded, i get the image through an AsyncTask, then i call an Activity's method to set the image that was just retrieved.

((ImageView)findViewById(R.id.raccdetailimage)).setImageDrawable((Drawable)vect.elementAt(0));

The image is shown, but it's too small: i want it stretched to it's max. Since there's enough height to stretch it, why doesn't it stretch the image? I have tryed to add the following code to the last code block but nothing changed.

        LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) ((ImageView)findViewById(R.id.raccdetailimage)).getLayoutParams();
    params.width = LinearLayout.LayoutParams.MATCH_PARENT;
    params.height = LinearLayout.LayoutParams.WRAP_CONTENT;
    ((ImageView)findViewById(R.id.raccdetailimage)).setLayoutParams(params);
mark
  • 939
  • 2
  • 13
  • 36
  • android will not stretch a small image but it will scale a big image to screen size by default in order to scale a image you need to apply other techniques and believe me they are not so reliable – Illegal Argument Jun 03 '14 at 15:26
  • 1
    You can add a custom ImageView to scale your image to the max width you can see this exemple it works fine http://stackoverflow.com/a/18077714/2764682 – wSakly Jun 03 '14 at 15:26
  • In the main activity i use the same image and it's larger. Is it possible? I have checked the pixel size and it's the same – mark Jun 03 '14 at 18:21

0 Answers0