java - Remove padding in horizontal progress bar -


in our application need indeterminate progress bar, so:

progress bar how should be

we can achieve setting negative margin on progressbar, this:

<progressbar     android:id="@+id/progressbar"     style="?android:attr/progressbarstylehorizontal"     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:indeterminate="true"     android:margintop="-7dp"     android:visibility="@{loading ? view.visible : view.gone}" /> 

but because constraintlayout not support negative margins, this:

progress bar padding

ok, negative margin hack. let's replace different hack, shall we? let's introduce our custom view customprogressbar, extends progressbar , overrides ondraw method, this:

@override protected void ondraw(canvas canvas) {     int margintop = dptopx(7);     canvas.translate(0, -margintop);     super.ondraw(canvas); } 

but of smells bad code. there has better solution! recommend?

another way use guideline , center progressbar between parent top , guideline.

<progressbar     android:id="@+id/progressbar2"     style="?android:attr/progressbarstylehorizontal"     android:layout_width="0dp"     android:paddingtop="-4dp"     android:layout_height="wrap_content"     app:layout_constraintright_torightof="parent"     app:layout_constraintleft_toleftof="parent"     app:layout_constraintbottom_totopof="@+id/guideline"     app:layout_constrainttop_totopof="parent" />  <android.support.constraint.guideline     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:id="@+id/guideline"     android:orientation="horizontal"     app:layout_constraintguide_begin="4dp" /> 

Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -