2014-06-18 51 views
0

我想在處理請求時用progressBar替換圖像按鈕。如何在等待請求時用progressBar替換imageButton?

這裏是我的XML

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:paddingLeft="@dimen/gap_normal" 
    android:orientation="horizontal" 
    android:background="0000000000"> 


    <com.devspark.robototextview.widget.RobotoTextView 
     android:id="@+id/conference_text_lockstate" 
     android:layout_width="0dp" 
     android:layout_weight="1" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="@dimen/gap_normal" 
     android:layout_marginBottom="@dimen/gap_normal" 
     android:gravity="left" 
     android:textSize="@dimen/textsize_normal" 
     android:paddingRight="@dimen/gap_large" 
     android:text="Unlocked. When all participants have joined, lock the conference by tapping the padlock." 
     app:typeface="roboto_condensed_regular" /> 


    <ImageButton 
     android:id="@+id/conference_checkableimagebutton_lockstate" 
     android:layout_width="60dp" 
     android:layout_height="match_parent" 
     android:scaleType="fitCenter" 
     android:adjustViewBounds="true" 
     android:background="@android:color/white" 
     android:src="@drawable/conference_checkableimagebutton_lockstate_src" 
     android:cropToPadding="false"/> 


    <ProgressBar 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/pb" 
     android:indeterminate="true" 
     android:visibility="invisible" 
     /> 




</LinearLayout>  

,我嘗試與進度在onclick方法來交換圖像按鈕。

  if (mLockCheckableImageButton.isChecked()==true){ 

       mLockCheckableImageButton.setClickable(false); 

       ProgressBar pb = (ProgressBar)inflated.findViewById(R.id.pb); 

       pb.setVisibility(View.VISIBLE);  

     //more code here. 

但是,這增加了他們旁邊的彼此。任何人?先謝謝你。

+0

使用相對或框架佈局... –

+0

如果你只是想更換,然後forgott調用mLockCheckableImageButton.setVisibility(View.GONE); – Opiatefuchs

回答

0

試試這個!

mLockCheckableImageButton.setOnClickListener(new View.OnClickListener() { 

       @Override 
       public void onClick(View v) { 
        // TODO Auto-generated method stub 
           mLockCheckableImageButton.setVisibility(View.GONE);  
        pb.setVisibility(View.VISIBLE);  

       } 
     }); 
2

您將ProgressBar的可見性設置爲visible。但是你不改變ImageButton的可見性。這就是爲什麼他們都顯示。

首先,你應該使用RelativeLayoutFrameLayout所以這些視圖可以在相同的位置(與LinearLayout他們將並排)。然後創建方法來顯示這些元素之一:

private void showProgressBar() { 
    myProgressBar.setVisibility(View.VISIBLE); 
    myImageButton.setVisibility(View.INVISIBLE); 
} 

private void showImageButton() { 
    myProgressBar.setVisibility(View.INVISIBLE); 
    myImageButton.setVisibility(View.VISIBLE); 
} 
1
Private void showProgressBar() { 
myProgressBar.setVisibility(View.VISIBLE); 
myImageButton.setVisibility(View.GONE); 
} 

private void showImageButton() { 
myProgressBar.setVisibility(View.GONE); 
myImageButton.setVisibility(View.VISIBLE); 
}