Custom View Android Basic Example
Activity.java
\res\layout\main.xml
location TouchImageView\src\cz\okhelp\TouchImageView\TouchImageView.java
public class A extends Activity{
Bitmap bm;
TouchImageView touch;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
bm = BitmapFactory.decodeResource(getResources(), R.drawable.chinese_sky_map);
touch = (TouchImageView)findViewById(R.id.myImageView);
touch.setImageBitmap(bm);
}
}
\res\layout\main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="//schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello" />
<cz.okhelp.TouchImageView.TouchImageView
android:id="@+id/myImageView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>
location TouchImageView\src\cz\okhelp\TouchImageView\TouchImageView.java
public class TouchImageView extends ImageView {
Context context;
// constructor wihtout using *.xml file
// public TouchImageView(Context context) {
// super(context);
// }
// constructor with xml file
public TouchImageView(Context context, AttributeSet attrs)
{
super(context, attrs);
super.setClickable(true);
this.context = context;
}
}
396LW NO topic_id
AD
Další témata ....(Topics)
android:gravity="left|center_vertical" or android:gravity="right|center_vertical"
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left|center_vertical"
android:paddingLeft="20dp"
android:text="My Button"
/>
On Android device is path to *.apk like this example:
How get package *.apk path on device dynamically Android example
/data/app/cz.okhelp.my_package.apk
How get package *.apk path on device dynamically Android example
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
String sPackagePath = getPackageResourcePath();
}
Long press by finger on screen
From dialogue select Widgets
Select your widget
Put your widget on the screen
Video tutorial - to add home screen widgets - Android 2.1
From dialogue select Widgets
Select your widget
Put your widget on the screen
Video tutorial - to add home screen widgets - Android 2.1
Full Screen without titlebar and statusbar for Android Activity.
In Activity.java
or in AndroidManifest.xml
In Activity.java
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main);
}
or in AndroidManifest.xml
<activity android:name=".ActivityName"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
</activity>
PNG, GIF, BMP, JPG
// //www.apache.org/licenses/LICENSE-2.0
// 1.) Bitmap from stream
InputStream is = context.getResources().openRawResource(R.drawable.my_image);
mBitmap = BitmapFactory.decodeStream(is);
// 2.)
Bitmap ball = BitmapFactory.decodeResource(getResources(), R.drawable.ball);
int dstWidth =120;
int dstHeight = 120;
mBitmap = Bitmap.createScaledBitmap(ball, dstWidth, dstHeight, true);
// 3.)
Bitmap mBitmap = Bitmap.createBitmap(320, 480, Bitmap.Config.ARGB_8888);
Bitmap mBitmap;
Canvas mCanvas;
Paint mBitmapPaint;
mBitmap = Bitmap.createBitmap(320, 480, Bitmap.Config.ARGB_8888);
mCanvas = new Canvas(mBitmap);
mBitmapPaint = new Paint(Paint.DITHER_FLAG);
// 4.)
Bitmap mBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.RGB_565);
Canvas mCanvas.setBitmap(mBitmap);
mCanvas.drawColor(0xFFFFFFFF);
Editace: 2012-02-14 21:11:33
Počet článků v kategorii: 396
Url:custom-view-android-basic-example