2014-09-24 7 views
0

ImageView 및 ProgressBar라는 두 개의 자식이있는 상대 레이아웃이 있습니다. ImageView의 이미지가로드되는 동안 회전 진행률 표시 줄을 표시하고 이미지가 완료되면 진행률 막대를 숨기고 이미지를 표시하려고합니다. 이미지를 표시 할 수는 없지만 진행률 표시 줄은 잘 보입니다.RelativeLayout에 ImageView 표시/숨기기

이 내 레이아웃 파일

<?xml version="1.0" encoding="utf-8"?> 
    <RelativeLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:gravity="center"> 
     <ImageView 
      android:layout_width="110dp" 
      android:layout_height="110dp" 
      android:visibility="visible"/> 
     <ProgressBar 
      android:layout_width="110dp" 
      android:layout_height="110dp"/> 
    </RelativeLayout> 

로드 이미지입니다 ... ... 나는 이미지가로드되고 있음을 확인했습니다,이 레이아웃 문제처럼 보이지만 나를 넘어

final RelativeLayout relLayout = (RelativeLayout)convertView; 
final ImageView imageView = (ImageView)relLayout.getChildAt(0); 
final ProgressBar bar = (ProgressBar)relLayout.getChildAt(1); 

bar.setIndeterminate(true); 
bar.setVisibility(View.VISIBLE); 
imageView.setVisibility(View.GONE); 

그리고 내에서는 imageLoader의는 onSuccess 내부

bar.setVisibility(View.GONE); 
imageView.setVisibility(View.VISIBLE); 
imageView.setImageBitmap(resizedBitmap); 
relLayout.requestLayout(); // also tried invalidate(), and nothing at all 

도움 말? 가시성 = "사라"

답변

1

그냥 또한 XML에 this link.

+0

이 실제로 정답이었다 도움이 ... 놀랐습니다. 나는 그것을 INVISIBLE로 설정하면 여전히 레이아웃 공간을 예약 할 수 있다는 인상하에 있었고, 이것이 내가 GONE으로가는 이유입니다. INVISIBLE로 전환하자마자 스피너 또는 이미지를 쉽게 숨기거나 표시 할 수있었습니다. – user2997084

+0

나는 한 번 그 문제에 직면했습니다. 나는 그것을했고 문제는 해결되었다. 왜이 솔루션은 downvoted 이해가 안 돼요. 이상한 사람들... –

0

먼저 확인 귀하의 이미지 뷰에 안드로이드를이 줄을 넣어

imageView.setVisibility(View.GONE);

imageView.setVisibility(View.INVISIBLE);

로 변경

는 그런 다음 코드로 progressBarr를 표시하려면 asynkTask를 사용하고 다운로드 마무리가 이미지 뷰를 proogressBar을 숨기고 보여줄 때 희망

public void getImage(){ 
    new AsyncTask<Void, Void, Boolean>(){ 
     @Override 
     protected Boolean doInBackground(Void... params){ 
     //Code to load image, take care don't change the UI because it can break the app 
     } 
     @Override 
     protected void onProgressUpdate(Integer... values){ 
     //Here you can update your progressBar 
     } 
     @Override 
     public void onPostExecute(Boolean result){ 
     //When the image finish the load here you can hide the progressBar and show the ImageView 
     bar.setVisibility(View.INVISIBLE); 
     imageView.setVisibility(View.VISIBLE); 
     } 
    }.execute(); 
} 

0
Try to keep id for the views because when the item is being gone, then the position of the view will get changed 
please try like this 

Your Layout: 
<?xml version="1.0" encoding="utf-8"?> 
    <RelativeLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:gravity="center"> 
     <ImageView 
      android:id="@+id/img_view" 
      android:layout_width="110dp" 
      android:layout_height="110dp" 
      android:visibility="visible"/> 
     <ProgressBar 
      android:id="@+id/progress_bar" 
      android:layout_width="110dp" 
      android:layout_height="110dp"/> 
    </RelativeLayout> 

In your java class: 

ImageView imgView = (ImageView)findviewbyId(R.id.img_view); 
ProgressBar progressBar = (ProgressBar)findviewById(R.id.progress_bar); 
imgView.setVisiblity(View.INVISIBLE); 
progressBar.setIndeterminate(true); 
In your oncomplete listener 
imgView.setVisibility(View.VISIBLE); 
progressBar.setVisibility(VIEW.INVISBLE); 
관련 문제