• 6
name

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191

Backtrace:

File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

Context: I want to build a horizontal progress bar with some values and want to put some text that move along below this progress bar. So my final ideia is something like this (I already have the progress bar built I only left the text views below)

Progress bar with text views below

My current code is something like this:

This is my StackedHorizontalProgressBar class:

public class StackedHorizontalProgressBar extends ProgressBar {
  private Paint paint;
  int primary_progress, max_value;

  public StackedHorizontalProgressBar(Context context) {
    super(context);
    init();
  }

  public StackedHorizontalProgressBar(Context context, AttributeSet attrs) {
    super(context, attrs);
    init();
  }

  @Override public synchronized void setMax(int max) {
    this.max_value = max;
    super.setMax(max);
  }

  @Override public synchronized void setProgress(int progress) {
    if (progress > max_value) {
      progress = max_value;
    }
    this.primary_progress = progress;
    super.setProgress(progress);
  }



  @Override public synchronized void setSecondaryProgress(int secondaryProgress) {
    if ((primary_progress + secondaryProgress) > max_value) {
      secondaryProgress = (max_value - primary_progress);
    }
    super.setSecondaryProgress(primary_progress + secondaryProgress);
  }

  private void init() {
    paint = new Paint();
    paint.setColor(Color.BLACK);
    primary_progress = 0;
    max_value = 100;
  }
}

This is my Main Activity layout (that uses above class)

<android.support.constraint.ConstraintLayout
    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"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity">

  <github.nisrulz.stackedhorizontalprogressbar.StackedHorizontalProgressBar
      android:id="@+id/stackedhorizontalprogressbar"
      style="?android:attr/progressBarStyleHorizontal"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_marginTop="16dp"
      android:progressDrawable="@drawable/stacked_horizontal_progress"
      app:layout_constraintTop_toTopOf="parent"
      tools:layout_editor_absoluteX="16dp" />

</android.support.constraint.ConstraintLayout>

This is my MainActivity class:

public class MainActivity extends AppCompatActivity {

    int max = 100;
    int countPrimary = 20;
    int countSecondary = 30;
    StackedHorizontalProgressBar stackedHorizontalProgressBar;

    TextView txt_primary, txt_secondary;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        stackedHorizontalProgressBar =
                (StackedHorizontalProgressBar) findViewById(R.id.stackedhorizontalprogressbar);
        stackedHorizontalProgressBar.setMax(max);

        stackedHorizontalProgressBar.setProgress(countPrimary);
        txt_primary.setText("Primary Value : " + countPrimary + "%");

        stackedHorizontalProgressBar.setSecondaryProgress(countSecondary);
        txt_secondary.setText("Secondary Value : " + countSecondary + "%");

    }

}

I think I must use canvas for this, so if there is anyone with experience with this that can help me.

public class ProgressBarAvtivity extends AppCompatActivity {
ProgressBar progressBar;
TextView tvProgress;
    int d = 1;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_progress_bar_avtivity);
        progressBar = (ProgressBar) findViewById(R.id.progressBar);
        progressBar.setProgress(d);
        tvProgress = (TextView)findViewById(R.id.tvProgress);
        tvProgress.setText(String.valueOf(d));
        if (d > 40) {
        tvProgress.setX(((width )* d / 100) - (d/2));
         } 
        else {
        tvProgress.setX(((width )* d / 100));

    }
 }}
  • 1
Reply Report
      • 2
    • I am statically setting the progress, so i have used d. you can change it according to your code. textview.setX() will place the textview below progressbar's progress.