본문 바로가기
안드로이드 자바

[Java][Android] 안드로이드 막대 그래프 만들기

by teamnova 2022. 3. 31.
728x90

ComparingPerformanceBar 라이브러리를 사용해서, 독특한 막대그래프를 만들어보겠습니다.

 

build.gradle(Module)

dependencies {
    ...
    implementation 'io.github.cliffgr:cpbar:1.1.0'
    ...
    }

 

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:gravity="center"
    android:layout_height="match_parent">

    <com.cliff.comparingperformancebar.PercentageProgressBar
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_marginStart="8dp"
        android:layout_marginEnd="8dp"
        android:id="@+id/chart"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:percentage="50"
        app:progressLeftColor="#77B9C1"
        app:progressRightColor="#45718B"
        app:textSize="18sp" />


</androidx.constraintlayout.widget.ConstraintLayout>

MainActivity.java

public class MainActivity extends AppCompatActivity {

    PercentageProgressBar valueProgressBar;

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

        valueProgressBar = findViewById(R.id.chart);
        valueProgressBar.setProgress((float) 34);
    }
}