Create Bitmap with Linear Gradient Android example
public class ApokusActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new SampleView(this));
}
private static class SampleView extends View {
// CONSTRUCTOR
public SampleView(Context context) {
super(context);
setFocusable(true);
}
@Override
protected void onDraw(Canvas canvas) {
Paint paint = new Paint();
canvas.drawColor(Color.GREEN);
Bitmap b = Bitmap.createBitmap(200, 200, Bitmap.Config.ALPHA_8);
paint.setColor(Color.BLUE);
Shader mShader = new LinearGradient(0, 0, 100, 70, new int[] {
Color.RED, Color.GREEN, Color.BLUE },
null, Shader.TileMode.MIRROR); // CLAMP MIRROR REPEAT
Canvas c = new Canvas(b);
paint.setShader(mShader);
//c.drawCircle(60, 60, 30, paint);
c.drawRect(0, 0, 200, 200, paint);
canvas.drawBitmap(b, 10,10, paint);
}
}
}

396LW NO topic_id
AD
Další témata ....(Topics)
LayoutLib is too recent. Update your tool!
Eclipse Android Graphical layout resolving problem.
Eclipse Android Graphical layout resolving problem.
- Open in Eclipse menu Help ->Check for Updates
- Select updates:
- Press Next and update all
- Restart Eclipse
[caption id="attachment_596" align="alignleft" width="300" caption="Restart Eclipse if updates finished."]

Android development
Java float is 32 bit single precision type and used when fractional precision calculation is required.
Java float je 32 bitů veliké číslo sloužící především pro přesný výsledek za desetinnou tečkou například při dělení čísel. Pro větší přesnost použíijte 64 bitový typ Double.
Java float is 32 bit single precision type and used when fractional precision calculation is required.
Java float je 32 bitů veliké číslo sloužící především pro přesný výsledek za desetinnou tečkou například při dělení čísel. Pro větší přesnost použíijte 64 bitový typ Double.
// declaration and assignment of value type float
float x = 18.41785f;
//print formated value
System.out.printf("The value of x is %.3f%n", x); // 18.418
// declaring more variables in single statement
float f1 = 12.4F, f2 = 564.5F, f3 = 14.589F;
// float range of value
System.out.println(Float.MIN_VALUE); // 4E-45
System.out.println(Float.MAX_VALUE); // 4028235E38
// is NaN Not-a-Number
float f = (float) Math.sqrt(-15);
boolean bNaN = Float.isNaN(f);
System.out.print(bNaN); // true
// check if a string is a valid number in Java example
// convert string to float Java example
String sF = "12.8";
float fParse = Float.parseFloat(sF);
// convert strings to numbers
String sFl = "15.48";
float fFromString = (Float.valueOf(sFl)).floatValue();
// float to string in Java example code
Float fObj = new Float(68.5);
String str = fObj.toString();
// else
Float fS = 11.6f;
String sFloat = fS.toString();
// compare two float variables
Float fComp1 = 4.3f;
if(fComp1.equals(4.3f))
System.out.print("true");
// compares the two specified float values in Java example
int i = Float.compare(11.5f, 11.7f); // -1 first < second
// 0 first == second
// 1 first > second
System.out.print(i);
Show keyboard if WebView input have focus Android apps development example source code.
WebView webview;
//in onCreate
webview = (WebView) findViewById(R.id.idWebviewPda);
webview.getSettings().setJavaScriptEnabled(true);
webview.loadUrl("//android.okhelp.cz");
webview.requestFocus(View.FOCUS_DOWN);
webview.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_UP:
if (!v.hasFocus()) {
v.requestFocus();
}
break;
}
return false;
}
});
Zipalign.exe path on Windows:
c:\Program Files\Android\android-sdk-windows\tools\zipalign.exe
How do signs .apk with your private key - image:
More about Zipalign android.com
c:\Program Files\Android\android-sdk-windows\tools\zipalign.exe
zipalign [-f] [-v] <alignment> infile.apk outfile.apk
// command line in Total Commander
zipalign.exe -f -v 4 infile.apk outfile.apk
When using Eclipse with the ADT plugin, the Export Wizard will automatically zipalign your .apk after it signs it with your private key.
How do signs .apk with your private key - image:





More about Zipalign android.com
// file name MyFirstClass.java
import java.util.*;
import java.lang.Math;
import java.io.*;
import javax.swing.*;
public class MyFirstClass{ // start of program
public static void main(String[] args) { // basic function main
// variables and calculation
int a=2;
int b=3;
int c=Integer.parseInt(JOptionPane.showInputDialog(" Put number: ", "1"));
System.out.println("Number is: "+c);
System.out.println(a+" * "+b+" = "+(a*b));
System.out.println("a^3 "+Math.pow(a,b));
//array
int[] array_my=new int[10];
array_my[0]=3;
array_my[1]=5;
System.out.println("Number of elements "+array_my.length+" 1 + 2 element of array "+(array_my[0]+array_my[1]));
//strings
String txt="Quick red fox";
String txt2=JOptionPane.showInputDialog("Write text: ", "word");
System.out.println("Text is: "+txt2);
String[] count_of_word=txt.split(" ");
System.out.println("Length: "+txt.length()+" Count of words "+count_of_word.length);
System.out.println(txt +" -> "+txt.replace("red","brown"));
System.out.println("First 5 chars of string is: "+ txt.substring(0,5));
//for a if
for(int i=0; i<10;i++){
if(i==3)System.out.println("i equal "+i);
}
// file
try {
File soubor=new File("some_file.txt");
if(!soubor.exists()){
System.out.println("File dont exist");
}
else { // utf-8 encoding
BufferedReader in1 = new BufferedReader(new InputStreamReader(new FileInputStream(soubor),"UTF-8"));
BufferedWriter out1 = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("zapis.txt"),"UTF-8"));
String str;
while ((str = in1.readLine())!=null){
System.out.println(str);
out1.write(str+"
");
}
in1.close();
out1.close();
}
} catch(IOException e){System.out.println("Error " + e);}
// dir
File pathName = new File("some_dir");
String[] fileNames = pathName.list();
if(pathName.exists())
System.out.println("Name of first file in "some_dir": "+fileNames[0]);
else System.out.println("dir not exist");
//function
int nResult = calculateMyFc(3,5);
System.out.println("Result of function: "+nResult);
} // end of function main
// new function , you can add to end MyFc = my function
public static int calculateMyFc(int a, int b){
return (a+b);
}
} // end of class of program
Editace: 2013-12-09 13:10:18
Počet článků v kategorii: 396
Url:create-bitmap-with-linear-gradient-android-example