gpt4 book ai didi

java - 如何设置 PieChart 中的字体大小?

转载 作者:行者123 更新时间:2023-12-01 09:10:44 26 4
gpt4 key购买 nike

我们有一个带有饼图的 Activity 页面。目前,每个部分的字体都非常小。

Our pie chart with its small font size

这是我们的代码:

package tech.pattullo.teamzero;

import android.graphics.Color;
import android.graphics.EmbossMaskFilter;
import android.graphics.PointF;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.SeekBar;
import android.widget.TextView;

import com.androidplot.pie.PieChart;
import com.androidplot.pie.PieRenderer;
import com.androidplot.pie.Segment;
import com.androidplot.pie.SegmentFormatter;
import com.androidplot.util.PixelUtils;

import java.util.List;


public class Statistics extends AppCompatActivity {

DatabaseHelper stats = new DatabaseHelper(this);

public static final int SELECTED_SEGMENT_OFFSET = 50;

private TextView donutSizeTextView;
private SeekBar donutSizeSeekBar;

public PieChart pie;

private Segment s1;
private Segment s2;
private Segment s3;
private Segment s4;

public Statistics() {

}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_statistics);
Log.i("STATISTICS", "Switched to statistics panel.");

pie = (PieChart) findViewById(R.id.myPie);

final float padding = PixelUtils.dpToPix(30);
pie.getPie().setPadding(padding, padding, padding, padding);

pie.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
PointF click = new PointF(motionEvent.getX(), motionEvent.getY());
if (pie.getPie().containsPoint(click)) {
Segment segment = pie.getRenderer(PieRenderer.class).getContainingSegment(click);
final boolean isSelected = getFormatter(segment).getOffset() != 0;
deselectAll();
setSelected(segment, !isSelected);
pie.redraw();
}
return false;
}

private SegmentFormatter getFormatter(Segment segment) {
return pie.getFormatter(segment, PieRenderer.class);
}

private void deselectAll() {
List<Segment> segments = pie.getSeriesRegistry().getSeriesList();
for (Segment segment : segments) {
setSelected(segment, false);
}
}

private void setSelected(Segment segment, boolean isSelected) {
SegmentFormatter f = getFormatter(segment);
if (isSelected) {
f.setOffset(SELECTED_SEGMENT_OFFSET);
} else {
f.setOffset(0);
}
}
});

donutSizeSeekBar = (SeekBar) findViewById(R.id.donutSizeSeekBar);
donutSizeSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
}

@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}

@Override
public void onStopTrackingTouch(SeekBar seekBar) {
pie.getRenderer(PieRenderer.class).setDonutSize(seekBar.getProgress() / 100f,
PieRenderer.DonutMode.PERCENT);
pie.redraw();
updateDonutText();
}
});
donutSizeTextView = (TextView) findViewById(R.id.donutSizeTextView);
updateDonutText();

s1 = new Segment("s1", 3);
s2 = new Segment("s2", 1);
s3 = new Segment("s3", 7);
s4 = new Segment("s4", 18);

EmbossMaskFilter emf = new EmbossMaskFilter(
new float[]{1, 1, 1}, 0.4f, 10, 8.2f);

SegmentFormatter sf1 = new SegmentFormatter(this, R.xml.pie_segment_formatter1);
sf1.getLabelPaint().setShadowLayer(3, 0, 0, Color.BLACK);
sf1.getFillPaint().setMaskFilter(emf);

SegmentFormatter sf2 = new SegmentFormatter(this, R.xml.pie_segment_formatter2);
sf2.getLabelPaint().setShadowLayer(3, 0, 0, Color.BLACK);
sf2.getFillPaint().setMaskFilter(emf);

SegmentFormatter sf3 = new SegmentFormatter(this, R.xml.pie_segment_formatter3);
sf3.getLabelPaint().setShadowLayer(3, 0, 0, Color.BLACK);
sf3.getFillPaint().setMaskFilter(emf);

SegmentFormatter sf4 = new SegmentFormatter(this, R.xml.pie_segment_formatter4);
sf4.getLabelPaint().setShadowLayer(3, 0, 0, Color.BLACK);
sf4.getFillPaint().setMaskFilter(emf);

pie.addSegment(s1, sf1);
pie.addSegment(s2, sf2);
pie.addSegment(s3, sf3);
pie.addSegment(s4, sf4);

pie.getBorderPaint().setColor(Color.TRANSPARENT);
pie.getBackgroundPaint().setColor(Color.TRANSPARENT);
}

protected void updateDonutText() {
donutSizeTextView.setText(donutSizeSeekBar.getProgress() + "%");
}

private void getUserData() {

}

void displayStats() {

}

void analyzeData() {

}

String offerSuggestions() {
int number = 6;
String message;

if (number > 5)
message = "You should get out more!";
else
message = "Keep doing what you're doing!";

return message;
}
}

为了添加一些细节,我们使用 com.androidplot.pie 库。我尝试查看文档,但没有任何东西可以接近设置字体大小。我对此无能为力吗?

最佳答案

您应该能够通过设置 labelPaint.textSize 来设置段格式化程序的 xml 中的字体大小

https://github.com/halfhp/androidplot/blob/36933d2639b5f9ff49f4b7aaca8a9a0d4f87fd40/demoapp/src/main/res/xml/pie_segment_formatter1.xml

关于java - 如何设置 PieChart 中的字体大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40938809/

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