这看起来应该有些微不足道,但是在我的Android应用程序中,我使用画布绘制一系列连接在一起的线条。由于某种原因,我的线条非常微弱和薄。我想知道如何让我的线条变粗?这是我的代码..
for(int i=1; i<myArrayListOfValues.size(); i++){
Paint myPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
myPaint.setStrokeWidth(8/*1 /getResources().getDisplayMetrics().density*/);
myPaint.setColor(0xffff0000); //color.RED
canvas.drawLine(myArrayListOfValues.get(i), myArrayListOfValues.get(i), myArrayListOfValues.get(i-1), myArrayListOfValues.get(i-1), myPaint);
}
另一件事是我绘制的线条和圆圈总是黑色的.setColor()似乎从来没有任何效果。我尝试过使用颜色名称(例如color.red)甚至是十六进制值(例如0xffff0000)
答案 0 :(得分:28)
更改
的值myPaint.setStrokeWidth(50);
为更大的整数,例如:
import java.awt.Color;
import java.awt.Container;
import javax.swing.*;
import javax.swing.event.MenuEvent;
import javax.swing.event.MenuListener;
class menuListener implements MenuListener {
@Override
public void menuSelected(MenuEvent e) {
// TODO Auto-generated method stub
System.out.println("menu clicked !");
System.exit(0);
}
@Override
public void menuDeselected(MenuEvent e) {
// TODO Auto-generated method stub
}
@Override
public void menuCanceled(MenuEvent e) {
// TODO Auto-generated method stub
}
}
public class pcMain extends JFrame implements Runnable {
userSeat us;
int user;
JPanel[] userSeat;
Container con;
JPanel leftPane, rightPane;
JMenuBar jm;
JMenu exit;
public pcMain(int user) {
super("Pc Management Application");
con = getContentPane();
con.setBackground(new Color(0, 128, 128));
setVisible(true);
setSize(1100, 500);
// setLayout(null);
this.setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Menu bar
jm = new JMenuBar();
// Menu items
exit = new JMenu("EXIT");
exit.addMenuListener(new menuListener());
// letPanel
leftPane = new JPanel();
leftPane.setLayout(null);
// leftPane.setSize(800, 470);
leftPane.setBorder(BorderFactory.createLineBorder(Color.black));
leftPane.setOpaque(false);
leftPane.setBounds(0, 0, 800, 500);
// rightPanel
rightPane = new JPanel();
// rightPane.setSize(300, 470);
rightPane.setBorder(BorderFactory.createLineBorder(Color.red));
rightPane.setOpaque(false);
rightPane.setBounds(800, 0, 300, 500);
// adding all components
this.user = user;
jm.add(exit);
us = new userSeat(user);
userSeat = us.getSeat();
setJMenuBar(jm);
// add(leftPane);
// add(rightPane);
}
@Override
public void run() {
int seatX = 10;
int seatY = 10;
// Add user seats into leftPane
for (int i = 0; i < user; i++) {
if (i != 0 && i % 5 == 0) {
// Increase y value
System.out.println("if : " + i);
seatX = 10;
seatY += 100;
}
// Increase x values
userSeat[i].setLocation(seatX, seatY);
leftPane.add(userSeat[i]);
// add(leftPane);
System.out.println("else :" + i);
seatX += 95;
}
add(leftPane);
}
public static void main(String[] args) {
new Thread(new pcMain(10)).start();
}
}
它会使线条变粗
答案 1 :(得分:18)
尝试在释放'mypaint'
后立即包含此行 mypaint.setStyle(Paint.Style.STROKE);
答案 2 :(得分:1)
如果删除ANTI_ALIAS_FLAG会怎样?此外,您应该将Paint构造函数移动到for循环之外,因此不会在每次迭代时重新创建它。