gpt4 book ai didi

java - Android水平矩形审阅栏

转载 作者:行者123 更新时间:2023-12-02 09:13:58 25 4
gpt4 key购买 nike

我正在努力创建一个矩形水平审查栏,这是我想要实现的目标的照片。

enter image description here

为此,我使用了 MPAAndroidChart,但我最终得到了这个,

enter image description here

代码:

public class MainActivity extends AppCompatActivity {

HorizontalBarChart skillRatingChart;

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

public void setSkillGraph(){
skillRatingChart = findViewById(R.id.skill_rating_chart);
skillRatingChart.setDrawBarShadow(false);
Description description = new Description();
description.setText("");
skillRatingChart.setDescription(description);
skillRatingChart.getLegend().setEnabled(false);
skillRatingChart.setPinchZoom(false);
skillRatingChart.setDrawValueAboveBar(false);


XAxis Xaxis = skillRatingChart.getXAxis();
Xaxis.setDrawGridLines(false);
Xaxis.setPosition(XAxis.XAxisPosition.BOTTOM);
Xaxis.setEnabled(true);
skillRatingChart.getXAxis().setDrawGridLines(false);
skillRatingChart.getAxisLeft().setDrawGridLines(false);
Xaxis.setDrawAxisLine(false);

final ArrayList<String> xLabels = new ArrayList<>();
xLabels.add("Pathetic");
xLabels.add("Poor");
xLabels.add("Average");
xLabels.add("Good");
xLabels.add("Excellent");
Xaxis.setValueFormatter(new XAxisValueFormatter(xLabels));
YAxis yright = skillRatingChart.getAxisRight();
yright.setDrawAxisLine(true);
yright.setDrawGridLines(false);
yright.isEnabled();

//Set bar entries and add necessary formatting
setGraphData();

//Add animation to the graph
skillRatingChart.animateY(2000);


}
public void setGraphData() {

//Add a list of bar entries
ArrayList<BarEntry> entries = new ArrayList<>();
entries.add(new BarEntry(0, 3f));
entries.add(new BarEntry(1, 8f));
entries.add(new BarEntry(2, 6f));
entries.add(new BarEntry(3, 30f));
entries.add(new BarEntry(4, 50f));
//Note : These entries can be replaced by real-time data, say, from an API

BarDataSet dataSet = new BarDataSet(entries,"Horizontal Bar");
BarData data = new BarData(dataSet);
skillRatingChart.setData(data);
skillRatingChart.animateXY(2000, 2000);
skillRatingChart.invalidate();
dataSet.setColors(ColorTemplate.COLORFUL_COLORS);
skillRatingChart.setDrawBarShadow(true);
dataSet.setBarShadowColor(Color.argb(40, 150, 150, 150));


}
}

任何帮助我都会很高兴!请帮助并告诉我如何将此图表更改为我想要实现的目标。

最佳答案

您可以使用此库在已内置的出色 UI 中显示评级

将其添加到您的项目级别 Gradle 文件中

allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}

将其添加到您的模块 Gradle 文件中

implementation 'com.github.Inconnu08:android-ratingreviews:1.2.0'

像这样添加评分和评论

RatingReviews ratingReviews = (RatingReviews) findViewById(R.id.rating_reviews);

int colors[] = new int[]{
Color.parseColor("#0e9d58"),
Color.parseColor("#bfd047"),
Color.parseColor("#ffc105"),
Color.parseColor("#ef7e14"),
Color.parseColor("#d36259")};

int raters[] = new int[]{
new Random().nextInt(100),
new Random().nextInt(100),
new Random().nextInt(100),
new Random().nextInt(100),
new Random().nextInt(100)
};

ratingReviews.createRatingBars(100, BarLabels.STYPE1, colors, raters);

有关更多正确的文档,请使用此链接 RatingReviews

关于java - Android水平矩形审阅栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59156907/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com