2016-09-15 64 views
0

那麼,我有1個活動,允許用戶上傳圖片(這取決於用戶上傳圖片與否)。我想只顯示該進度條,當用戶上傳照片:Android - 進度條練習

<LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:padding="10dp" 
     android:background="@color/wiColorQuiteBlack" 
     android:visibility="gone" 
     android:id="@+id/linear_progressBar" 
     android:orientation="horizontal"> 
      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:src="@drawable/ic_insert_drive_file_white_24dp"/> 
      <ProgressBar 
       android:id="@+id/wi_progress_uploading" 
       style="@style/Widget.AppCompat.ProgressBar.Horizontal" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center_vertical" 
       android:layout_marginStart="20dp" 
       android:indeterminate="false" 
       android:progressTint="@color/white" 
       android:max="100" 
       android:progress="0" /> 
    </LinearLayout> 

enter image description here

我做什麼:進度條是「水漲船高」,當用戶開始上傳圖片此更改「可見」..我的問題是:這是一個很好的做法?或者我應該以編程方式創建linearlayout + imageview + progressbar?

+0

嘗試使用異步它同樣 – siddhesh

+0

確實提供了你的功能你最喜歡的方式,你甚至可以使用ProgressDialog – Nitesh

+0

的東西是我不想使用ProgressDialog,因爲它不適合我的設計我上傳了一張我的進度條圖片 –

回答

1

這是一個更主觀的問題,但我會盡量保留儘可能多的XML視圖,這就是爲什麼我個人會建議將它設置爲View.GONE,然後在需要時將其設置爲可見。

這樣一來,你不會有太多的交叉與Java和XML的視圖邏輯。

使用Java語言編寫的意見只是簡單的吸過:(你這是使用腳本上傳