Reputation: 321
I'm trying to set the progress of a progress bar but it just keeps spinning, do I need to add something or how to I set it to be a certain percentage?
Code:
public class TabOverviewFragment extends Fragment {
@BindView(R.id.progressBar1)
ProgressBar progressBar1;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_tab_overview,
container,
false);
ButterKnife.bind(this, view);
progressBar1.setProgress(90);
return view;
}
public TabOverviewFragment() {
// Required empty public constructor
}
}
Layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".modinfosection.TabOverviewFragment">
<ProgressBar
android:id="@+id/progressBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:padding="30dp"
android:clickable="false"
android:scrollbarSize="300dp"/>
Upvotes: 4
Views: 7119
Reputation: 12138
Update ProgressBar
to this:
<ProgressBar
android:id="@+id/progressBar1"
style="@android:style/Widget.ProgressBar.Horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:padding="30dp"
android:clickable="false"
android:scrollbarSize="300dp"/>
You need to give ProgressBar
determinate style to use it as percent progress.
More from here : Reference
Upvotes: 1
Reputation: 69734
Add below property in your ProgressBar
android:indeterminateOnly="true"
if you want
Horizontal-ProgressBar
than use below property
style="@android:style/Widget.Holo.Light.ProgressBar.Horizontal"
SAMPLE CODE
<ProgressBar
android:id="@+id/progressBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:padding="30dp"
android:clickable="false"
android:indeterminateOnly="true"
style="@android:style/Widget.Holo.Light.ProgressBar.Horizontal"
android:scrollbarSize="300dp"/>
Upvotes: 0