我正在尝试创建一个逐渐从一种颜色到另一种颜色的弧(可变度数).例如从蓝色到红色:
这是我的代码:
SweepGradient shader = new SweepGradient(center.x, center.y, resources.getColor(R.color.startColor),resources.getColor(R.color.endColor));
Paint paint = new Paint()
paint.setStrokeWidth(1);
paint.setStrokeCap(Paint.Cap.FILL);
paint.setStyle(Paint.Style.FILL);
paint.setShader(shader);
canvas.drawArc(rectF, startAngle, sweepAngle, true, paint);
Run Code Online (Sandbox Code Playgroud)
但结果是整个弧线都涂上了相同的颜色.
编辑:
经过更多的实验,我发现颜色的扩散是由弧的角度决定的.如果我绘制一个小角度的圆弧,则只显示第一种颜色.角度越大,绘制的颜色越多.如果角度很小,似乎没有渐变.
这是一个例子.我画了4个弧--90,180,270和360:
RectF rect1 = new RectF(50, 50, 150, 150);
Paint paint1 = new Paint();
paint1.setStrokeWidth(1);
paint1.setStrokeCap(Paint.Cap.SQUARE);
paint1.setStyle(Paint.Style.FILL);
SweepGradient gradient1 = new SweepGradient(100, 100,
Color.RED, Color.BLUE);
paint1.setShader(gradient1);
canvas.drawArc(rect1, 0, 90, true, paint1);
RectF rect2 = new RectF(200, 50, 300, 150);
Paint paint2 = new Paint();
paint2.setStrokeWidth(1);
paint2.setStrokeCap(Paint.Cap.SQUARE);
paint2.setStyle(Paint.Style.FILL);
SweepGradient gradient2 = new SweepGradient(250, 100,
Color.RED, …
Run Code Online (Sandbox Code Playgroud) 我刚开始使用Log4Net库并且在配置时遇到问题.我不需要任何特别的东西.我将它用于Winforms应用程序,需要基本文件和控制台日志记录.为了保持尽可能简单,我使用App.config进行配置并使用从Log4Net项目网站获取的默认值:App.config:
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="ProjectFolder" value="D:\Documents\my documents\Themis\Projects"/>
</appSettings>
<configSections>
<section name="log4net"
type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
</configSections>
<log4net>
<appender name="LogFileAppender" type="log4net.Appender.FileAppender">
<param name="File" value="ThemisLog.txt" />
<param name="AppendToFile" value="true" />
<layout type="log4net.Layout.PatternLayout">
<param name="Header" value="[Header]\r\n" />
<param name="Footer" value="[Footer]\r\n" />
<param name="ConversionPattern" value="%d [%t] %-5p %c %m%n" />
</layout>
</appender>
<appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender" >
<layout type="log4net.Layout.PatternLayout">
<param name="Header" value="[Header]\r\n" />
<param name="Footer" value="[Footer]\r\n" />
<param name="ConversionPattern" value="%d [%t] %-5p %c %m%n" />
</layout>
</appender>
<root>
<level value="DEBUG" />
<appender-ref ref="LogFileAppender" /> …
Run Code Online (Sandbox Code Playgroud) 我有这个简单的布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<SurfaceView
android:id="@+id/surfaceView1"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight = "1" />
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="button1" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="button2" />
</LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
这符合并且应用程序运行完美.我想用我自己的自定义SurfaceView替换通用SurfaceView:
import android.content.Context;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
public class PuzzleView extends SurfaceView implements SurfaceHolder.Callback {
public PuzzleView(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width,
int height) {
// TODO Auto-generated method …
Run Code Online (Sandbox Code Playgroud) 我在这段代码上收到此错误:
super("Trace Masker");
setLayout(new BoxLayout(getContentPane(), BoxLayout.PAGE_AXIS));
label1 = new JLabel("Source directory:");
label2 = new JLabel("Target directory:");
label3 = new JLabel("Defect number:");
label4 = new JLabel("Slice tokens:");
label4.setToolTipText("Seperate multiple tokens with comma");
txtSourceDirectory = new JTextField(30);
txtTargetDirectory = new JTextField(30);
txtDefectNumber = new JTextField(30);
txtSliceTokens = new JTextField(30);
btnBrowseSourceDirectory = new JButton("...");
btnBrowseTargetDirectory = new JButton("...");
btnStart = new JButton("Start");
btnCancel = new JButton("Cancel");
pnlLabels = new JPanel(new BoxLayout(pnlLabels, BoxLayout.PAGE_AXIS));
pnlText = new JPanel(new BoxLayout(pnlText, BoxLayout.PAGE_AXIS));
pnlBrowseButtons = new JPanel(new BoxLayout(pnlBrowseButtons, …
Run Code Online (Sandbox Code Playgroud) 我是来自C#的java的新手,所以我不熟悉java最佳实践.
我有一个主类打开一个JFrame来从用户获取几个输入字符串.当用户单击提交时,GUI应该关闭,主类继续使用输入进行处理.
这是主要类:public class Main {
FInput fInput;
public void main(String[] args) {
if(args.length==0)
{
fInput = new FInput();
fInput.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fInput.pack();
fInput.setVisible(true);
}
else
startProcess(args);
}
public void startProcess(String[] args) {
// Do stuff
}
Run Code Online (Sandbox Code Playgroud)
主类将使用此框架从用户获取输入:
public class FInput extends JFrame{
private JTextField txtSourceDirectory;
private JTextField txtTargetDirectory;
private JTextField txtDefectNumber;
private JTextField txtSliceTokens;
private JButton btnStart;
public FInput() {
// Initialize text fields and button
JButton.addActionListener(something);
}
}
Run Code Online (Sandbox Code Playgroud)
在我能找到的所有例子中,听众本身就是一个FMain.但是在这种情况下,我希望Main监听并使用方法startProcess中的输入.
将Main实现ActionListener,并将其传递给FMain构造函数是可行的方法吗?新手问题 - 我正在编写我的第一个Android应用程序(它是我的第二个Java应用程序).我注意到在示例中该onCreate()
方法具有@Override
注释,但我没有使用该注释,它似乎工作正常.
使用@Override
注释是不错的做法,还是我为自己设置问题.其他继承的方法怎么样 - onPause
等等?
可能重复:
int []数组和int数组[]之间的差异
我在java教程中看到了这个例子:
private int puzzle[];
Run Code Online (Sandbox Code Playgroud)
这与我熟悉的"普通"声明类型不同:
private int[] puzzle;
Run Code Online (Sandbox Code Playgroud)
eclipse接受两者.这两个符号之间有区别吗?
我在DataGridView中显示一个最多100,000行的表.该表有一列包含大字符串.我发现该设置AutosizeMode
会AllCells
导致应用程序长时间冻结,同时计算所需的宽度.作为妥协,我将自动调整大小模式设置为DisplayedCells.然后我将一个方法绑定到dataGrid的scroll事件:
public void MethodThatBindsDataToTheDatagridview(DataTable table)
{
dataGrid.Source = table;
dataGrid.Columns[1].AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
dataGrid.Columns[2].AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
}
public void DataGridScroll(object sender, ScrollEventArgs e)
{
((DataGridView)sender).Update();
}
Run Code Online (Sandbox Code Playgroud)
我也尝试过同样的Refresh
方法.我的期望是DataGrid将根据显示的行设置列宽.但是,这只在加载表时发生一次,但滚动事件不会触发列宽的更改.
我正在对一个大文件进行替换操作.我遇到'('字符问题.这是我的方法:
public static string Replace(string input, string stringToMask, string mask)
{
return Regex.Replace(input, @"(?<![0-9])" + stringToMask + "(?![0-9])", mask);
}
Run Code Online (Sandbox Code Playgroud)
此字符串"BNY MELLON INVESTMENT SERVICING(IN"导致此错误:
parsing "(?<![0-9])BNY MELLON INVESTMENT SERVICING (IN(?![0-9])" - Not enough )'s.
Run Code Online (Sandbox Code Playgroud)
有什么办法可以避免吗?
我在尝试启动模拟器时遇到此错误:
[2011-10-21 16:25:02 - Emulator] Failed to allocate memory: 8
[2011-10-21 16:25:02 - Emulator]
[2011-10-21 16:25:02 - Emulator] This application has requested the Runtime to terminate it in an unusual way.
[2011-10-21 16:25:02 - Emulator] Please contact the application's support team for more information.
Run Code Online (Sandbox Code Playgroud)
我试图修改启动设置但没有成功:
4.0模拟器运行得很好.在Windows XP上运行.