mttkay / ignition

Kick-starts Android application development.
1.28k stars 290 forks source link

Load-spinner placed beside image (RemoteImageView) #28

Open petgru opened 12 years ago

petgru commented 12 years ago

Hi,

I have a problem with the load-spinner getting placed on the side of the image when using RemoteImageView from the latest version of the master bransch. This leads to that the View takes up twice the space it should.

I use the following code to initiate the image in my layout.

<com.github.ignition.core.widgets.RemoteImageView
            android:layout_width="64dip"
            android:layout_height="64dip"
            ignition:autoLoad="false"/>

I assign the url programmatically when the activity is created.

I use the latest version of the Android SDK and the problem seams to manifestate it self on all android versions (Tried it on 4.0, 2.2 and 2.3)

Regards Peter

Steven-Meyer commented 12 years ago

I came across this issue as well when trying to place a RemoteImageView in a vertical LinearLayout. The work around i came up with was instead of using a LinearLayout using a RelativeLayout and arranging my desired elements vertically as i wanted.

I think this error is occurring because of the following lines in RemoteImageView.java:

private void showProgressView(boolean show) {
        if (show) {
            state = STATE_LOADING;
            progressViewContainer.setVisibility(View.VISIBLE);
            setVisibility(View.INVISIBLE);
        } else {
            state = STATE_DEFAULT;
            progressViewContainer.setVisibility(View.INVISIBLE);
            setVisibility(View.VISIBLE);
        }
  }

The progressViewContainer is having it's visibility set to INVISIBLE, meaning that it is still taking up the room. Setting this to GONE should make the progressViewContainer disappear and not take up the room.

This space is an issue in a LinearLayout, because the two views are place next to each other (vertically or horizontally, depending). Where as with a RelativeLayout these two views are occupying the same space.

Steven-Meyer commented 12 years ago

Yes this is definitely the issue. Another easier work around is after the image is loaded call the following

remoteImageView.getProgressView().setVisibility(GONE);

This will allow you to put a remote imageview into a LinearLayout, with the expected behaviour

mttkay commented 12 years ago

Can someone post some code that reproduces this issue? We're building against the latest code from master and don't see this issue in our app.

Steven-Meyer commented 12 years ago

Here is a quick example i threw together:

have a layout file such as:

  <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ignition="http://github.com/ignition/schema"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:orientation="vertical" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="@dimen/padding_medium"
        android:text="@string/hello_world"/>
    <com.github.ignition.core.widgets.RemoteImageView
            android:id="@+id/remote_image"
            android:layout_width="100dip"
            android:layout_height="100dip"
            android:background="#000000"
            android:layout_marginTop="25dip"
            ignition:autoLoad="false"/>
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="@dimen/padding_medium"
        android:text="@string/hello_world"/>
</LinearLayout>

and a java file:

  package com.example.ignition_fix;

import com.github.ignition.core.widgets.RemoteImageView;

import android.os.Bundle;
import android.app.Activity;

public class MainActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        final RemoteImageView remoteImage = (RemoteImageView) findViewById(R.id.remote_image);
        remoteImage.setImageUrl("");
        try{
          remoteImage.loadImage();
        } catch(Exception e) {

        } 
   }
}

the Spinner loads below the image, and then when the image loads the space occupied by the spinner is still included in the layout space, causing the layout to be thrown off.