0

After rotation of device -> Image (id=list_image2) remains small like it was at portrate mode Seems it is because I change count of Columns gridView.setNumColumns(3);, but viewholder still contains previous imageview with previous width and height, also I tryed to make gridView.invalidate(); in onConfigurationChanged...but no result

added to activity in Manifest

  android:configChanges="keyboardHidden|orientation|screenSize"

Here is item_grid.xml

<?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/list_row_root"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:orientation="horizontal"
        android:paddingLeft="1dip"
        android:paddingRight="1dip"


 <ImageView
     android:id="@+id/list_image2"
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     android:layout_centerInParent="true"
     android:minWidth="@dimen/grid_item_width"
     android:minHeight="@dimen/grid_item_height"
     android:src="@drawable/ic_action_cloud"
     android:scaleType="fitXY"
    />

    <ProgressBar
        android:id="@+id/progressBar1"
        style="?android:attr/progressBarStyleLarge"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="30dp"

        android:layout_alignBottom="@+id/list_image2"
        android:layout_alignTop="@+id/list_image2"
        android:layout_centerHorizontal="true" />

    <RelativeLayout
        android:id="@+id/likes_RelativeLayout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/field_likes"
        android:paddingTop="5dp"
        android:paddingBottom="5dp"
        android:paddingLeft="10dp"
        android:paddingRight="10dp"
        android:layout_alignBottom="@+id/list_image2"
        android:layout_alignRight="@+id/list_image2"
        android:layout_marginRight="4dp"
        android:layout_marginBottom="4dp" >

        <TextView
            android:id="@+id/likes"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:textColor="@android:color/white"
            android:text="265465" />

         <ImageView
             android:id="@+id/btn_favoutites"
             android:layout_width="25dp"
             android:layout_height="25dp"
             android:layout_centerVertical="true"
             android:layout_marginLeft="5dp"
             android:layout_toRightOf="@+id/likes"
             android:src="@drawable/btn_rating_star_on_normal_holo_dark"
             android:text="Button" />

    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/btn_RelativeLayout"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_alignBottom="@+id/likes_RelativeLayout"
        android:layout_alignLeft="@+id/likes_RelativeLayout"
        android:layout_alignRight="@+id/likes_RelativeLayout"
        android:layout_alignTop="@+id/likes_RelativeLayout"
        android:background="@drawable/field_like_clickable_style" >

    </RelativeLayout>

Here is my adapter:

publ

ic class LazyAdapter2 extends BaseAdapter{
    public LazyAdapter2(Context context, ArrayList<WallImage> d) {

            mContext = context;
            data=d;
            inflater = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

            imageLoader = ImageLoader.getInstance();
            options = new DisplayImageOptions.Builder()
                .cacheInMemory(true)
                .cacheOnDisk(true)
                .resetViewBeforeLoading(true)
                .imageScaleType(ImageScaleType.EXACTLY)// default
                .build();
        }

 public View getView( int position,  View convertView, ViewGroup parent) {
         final ViewHolderItem viewHolder;
        if(convertView==null)
        {
             convertView = inflater.inflate(R.layout.item_grid, null);
             viewHolder = new ViewHolderItem();
             viewHolder.thumb_image=(ImageView)convertView.findViewById(R.id.list_image2); // thumb image
             convertView.setTag(viewHolder);

        }else{
            viewHolder = (ViewHolderItem) convertView.getTag();
        }


        WallImage imageObject = data.get(position);
        viewHolder.likes.setText(imageObject.views);
        imageLoader.displayImage(imageObject.preview, viewHolder.thumb_image, options);

        return convertView;
    }

}

enter image description here

NickUnuchek
  • 11,794
  • 12
  • 98
  • 138
  • Just a sidenote, I know it's not an answer (that's why it's a comment): `android:configChanges="keyboardHidden|orientation|screenSize"` is a bad habit -- try to adapt to the orientation rather than avoid to consider it. – shkschneider Jan 13 '15 at 14:03
  • imageScaleType(ImageScaleType.EXACTLY); change it to .imageScaleType(ImageScaleType.EXACTLY_STRETCHED). It will helpful when image size is smaller. – Shabbir Dhangot Jan 13 '15 at 14:12
  • @SidDhangot no result – NickUnuchek Jan 13 '15 at 14:48

4 Answers4

1

Not just invalidate but how about like this with Handler.post()?:

new Handler(getMainLooper()).post(new Runnable() {
    @Override
    public void run() {
        gridView.invalidate();
    }
});
hata
  • 11,633
  • 6
  • 46
  • 69
0

Maybe this is due to the use of convertView in your getView method? It keeps the original layout and don't recreate it when orientation change.

You could add to your ViewHolderItem class a boolean member that indicates the screen orientation.

And when you recycle the view, you test your viewHolder orientation. If it's different from the current screen orientation, don't recycle it.

Groco
  • 1,301
  • 15
  • 19
0

Solved by changing of item_grid.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/list_row_root"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:orientation="horizontal"
    android:paddingLeft="1dip"
    android:paddingRight="1dip"
     >
     <ImageView
            android:id="@+id/list_image2"
            android:layout_width="match_parent"
            android:layout_height="@dimen/grid_item_height"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:scaleType="centerCrop"
            android:src="@android:color/transparent"
             />

after doing of ImageView android:layout_height="@dimen/grid_item_height" => after rotation of screen image size remains constant, but to resize imege in ImageView I use android:scaleType="centerCrop" after that image is slighly cutted , but problem is solved

NickUnuchek
  • 11,794
  • 12
  • 98
  • 138
0

Try imageScaleType(ImageScaleType.IN_SAMPLE_INT) and

imageLoader.displayImage(imageObject.preview, viewHolder.thumb_image, options);
viewHolder.thumb_image.setScaleType(ImageView.ScaleType.FILL_XY);
QArea
  • 4,955
  • 1
  • 12
  • 22