Okhelp.cz

Recepty, články, nápady, programování. Dříve dum-zahrada, finance, internet a know-how.okhelp.cz Pro lepší výsledky hledání používejte i diakritiku.

Custom View Android Basic Example

Activity.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)


121

Android button text alignment left right - sample | android-button-textalignment


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"
                     />

50

How get package resource apk path on device Android example | how-get-package-resource-path-android-example


On Android device is path to *.apk like this 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();
     }
269

How to Add Home Screen Widgets on Your Android Phone | how-to-add-home-screen-widgets-on-your-android-phone


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