Search code examples
javaandroidxmlandroid-imageviewresize-image

i Can't Resize Image in XML Android


Why I can't display images in a large size, its results even smaller, is there something wrong with my XML code? or errors are in the java code? And i have "[Accessibility] Missing contentDescription attribute on image" on my XML code in ImageView Poster

This my code :

Detail.xml

<ImageView
        android:id="@+id/ivPosterImage"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:adjustViewBounds="true"
        android:maxHeight="300dp"
        android:src="@drawable/large_movie_poster" />
    <ScrollView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/ivPosterImage"
        android:layout_marginTop="10dp" android:id="@+id/scrollView1">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical" >
        </LinearLayout>
    </ScrollView>

Activity.java

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_box_office_detail);
        // Fetch views
        ivPosterImage = (ImageView) findViewById(R.id.ivPosterImage);
        ....
Picasso.with(this).load(movie.getLargePosterUrl()).
            placeholder(R.drawable.large_movie_poster).
            into(ivPosterImage);

Please help me ...


Solution

  • Its clearly looking that your downloaded image have very small height and width dimension and you have settled the dimension around wrap_content. That's why you are getting this small icon instead of full image.

    And again image download libs always use image attribute setSource in their code, which also set image around wrap_content.

    Now you have 2 choice to show image wider:

    1. set width = match parent, height = fixed(any value as per your choice like 100 dp ,200 etc), i have not fixed the width because thats goona create exception on small or large screns.

    2. set image background instead of image src that is by default set by image download libs.

    Hopefully this will resolve your issue.