Rotate Canvas with Bitmap Android example
drawPath, canvas.rotate, lineTo basic Android example for your testing.
|
|
|
|
// //www.apache.org/licenses/LICENSE-2.0
// The Android Open Source Project
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new SampleView(this));
}
private static class SampleView extends View {
private Paint mPaint = new Paint();
private Path mPath = new Path();
// CONSTRUCTOR
public SampleView(Context context) {
super(context);
setFocusable(true);
// Construct a wedge-shaped path
mPath.moveTo(0, -60);
mPath.lineTo(-20, 80);
mPath.lineTo(0, 60);
mPath.lineTo(20, 80);
mPath.close();
}
@Override
protected void onDraw(Canvas canvas) {
Paint paint = mPaint;
canvas.drawColor(Color.WHITE);
paint.setAntiAlias(true);
paint.setColor(Color.RED);
paint.setStyle(Paint.Style.FILL);
Bitmap bitmapOrg = BitmapFactory.decodeResource(getResources(),
R.drawable.flower_blue);
canvas.drawBitmap(bitmapOrg, 10, 10, paint);
int w = canvas.getWidth();
int h = canvas.getHeight();
int cx = w / 2;
int cy = h / 2;
canvas.translate(cx, cy);
// uncomment next line
//canvas.rotate(90.0f);
canvas.drawPath(mPath, mPaint);
}
}
}
396LW NO topic_id
AD
Další témata ....(Topics)
The exact physical pixels per inch of the screen
Get size of pixel
Get DPI
Get count of pixels per inch
Get size of pixel
Get DPI
Get count of pixels per inch
float mXDpi;
float mYDpi;
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
mXDpi = metrics.xdpi; // The exact physical pixels per inch of the screen in the X dimension.
mYDpi = metrics.ydpi;
float mMetersToPixelsX = mXDpi / 0.0254f; // 1 inch == 0.0254 metre
float mMetersToPixelsY = mYDpi / 0.0254f;
xml RelativeLayout Android example:
Eclipse graphical xml layout editor
[caption id="attachment_896" align="alignleft" width="261" caption="Relativelayout Eclipse graphical editor"][/caption]
res/layout/main.xml
Eclipse graphical xml layout editor
[caption id="attachment_896" align="alignleft" width="261" caption="Relativelayout Eclipse graphical editor"][/caption]
res/layout/main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="//schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/idLabel"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Enter word"/>
<EditText
android:id="@+id/idEntry"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@android:drawable/editbox_background"
android:layout_below="@id/idLabel"/>
<Button
android:id="@+id/idOk"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/idEntry"
android:layout_alignParentRight="true"
android:layout_marginLeft="10dip"
android:text="OK" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/idOk"
android:layout_alignTop="@id/idOk"
android:text="Cancel" />
</RelativeLayout>
The Labeled continue statement as goto Java example.
public class MainClass {
public static void main(String[] arg) {
String[] arrayOfString = { "Hello", "people", "hello", "world!" };
OuterLoop: for (int e = 0; e < 4; e++) {
for (int i = 0; i < arrayOfString.length; i++) {
if (arrayOfString[i].equals("hello"))
continue OuterLoop;
System.out.println(arrayOfString[i]);
}
}
}
}
/*
Hello
people
Hello
people
Hello
people
Hello
people
*/
public boolean isConnected() {
try {
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
return cm.getActiveNetworkInfo().isConnectedOrConnecting();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
Log.e("isConnected", e.getMessage());
Toast.makeText(getApplicationContext(), e.getMessage(),
Toast.LENGTH_LONG).show();
return false;
}
Problem:
You have two class with similar names HeadLinesFragment and HeadMyLinesFragment with OnHeadlineSelectedListener.
Check if call correct class in MainActivity.
For example if use HeadMyLinesFragment change implement to HeadMyLinesFragment too!
You have two class with similar names HeadLinesFragment and HeadMyLinesFragment with OnHeadlineSelectedListener.
Check if call correct class in MainActivity.
For example if use HeadMyLinesFragment change implement to HeadMyLinesFragment too!
public class MainActivity extends FragmentActivity
implements HeadLinesFragment.OnHeadlineSelectedListener {
// wrong implements you need correct class name
//implements HeadMyLinesFragment.OnHeadlineSelectedListener
//............
HeadMyLinesFragment firstFragment = new HeadMyLinesFragment(); // because in code using HeadMyLinesFragment
Editace: 2013-12-09 13:08:53
Počet článků v kategorii: 396
Url:rotate-canvas-with-bitmap-android-example