Reputation: 247
Well, I have 1 activity that allow the user to upload picture (it depends on the user to upload pictures or not). I want to show this progress bar only when the user upload a picture:
<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>
What I do: The progress bar is "gone" and when the user start to upload a picture this change to "visible".. My question is: It is a good practice? Or should I create the linearlayout + imageview + progressbar programatically?
Upvotes: 0
Views: 141
Reputation: 496
This is more of a subjective question, but I would try to keep as much of the view in XML as possible, which is why I personally would recommend having it set to View.GONE
, then setting it to visible when it is needed.
This way, you won't have too much cross-over with the view logic in both Java and XML.
Writing views in Java just plain sucks too :(
Upvotes: 1