2016-09-15 65 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语言编写的意见只是简单的吸过:(你这是使用脚本上传