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.

Draw text drawText Android basic example


AD MOB

drawText(), setColor(), setTextSize(), setTextAlign()

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();
			
            paint.setColor(Color.YELLOW);
            paint.setTextSize(60);
            //paint.setTextAlign(Paint.Align.CENTER);

            canvas.drawText("Hello world!", 0, 50, paint);
		}

	}
}


397LW NO topic_id




AD

Další témata ....(Topics)


91

Class File Editor - Source not found - Change Attached Source - Eclipse | class-file-editor-source-not-found-change-attached-source-eclipse


The source attachment does not contain the source for the file TextWatcher.class.
You can change the source attachment by clicking Change Attached Source below:

You have to add JDK src.zip path to dialog as on image below.
[caption id="attachment_1091" align="alignleft" width="282" caption="class file editor source not found Eclipse warning"][/caption]



Or go to Project > Properties > Java Build Path > Libraries
Expand JRE System Library. Expand rt.jar.
Select Source attachment and double click or Edit.
Type path the source code file (External File…) and press OK.

[caption id="attachment_1094" align="alignleft" width="300" caption="Java project build path"][/caption]



Or type path in Java JRE definition



[caption id="attachment_1105" align="alignleft" width="300" caption="Java JRE deifiniton path in Eclipse"][/caption]

How open String.class or others keywords definition with Eclipse.



Now if mouse move about keywords String or F3 on keywords and press button in yellow field will opened String.class
Java Eclipse intellisense




Java-string-class-image
86

Map TreeMap key value pair add put get pair by key Java Android example | map-treemap-key-value-pair-add-put-get-pair-by-key-java-android-example


Map TreeMap add key value pair get find pair by key Java Android example.

MainClass.java

import java.util.Map;
import java.util.TreeMap;

public class MainClass {
	public static void main(String[] arg) {
		
		// english;germany dictionary
		String[] arrayOfString = { "one;eine", "two;zwei", "three;drei" };

		Map<String, String> map = new TreeMap<String, String>();
	    
		for(String s: arrayOfString){
	    	String[] array = s.split(";");
	    	String sKey ="", sValue="";
	    	if(array.length > 1){
	    	sKey = array[0]; sValue = array[1];
	    		map.put(sKey, sValue);
	    	}
	    }

       // check if key exists 	    
	   if( map.containsKey("two")){
		System.out.print("two = " + map.get("two"));
	   }
	}
}
/*
two = zwei
 */

208

Zipalign ADT Eclipse | zipalign-adt-eclipse


Zipalign.exe path on Windows:
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:


signs-apk-with-eclipse-android-1

signs-apk-with-eclipse-android-1

signs-apk-with-eclipse-android-1

signs-apk-with-eclipse-android-1

signs-apk-with-eclipse-android-1

More about Zipalign android.com
58

HorizontalScrollView ScrollView horizontal vertical Android xml example | horizontalscrollview-scrollview-horizontal-vertical-android-xml-example


HorizontalScrollView ScrollView LinearLayout horizontal vertical Android xml basic example and image.

[caption id="attachment_889" align="alignleft" width="200" caption="horizontal scrollview horizontalscrollview android"]horizontalscrollview-android[/caption]


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/LinearLayout01"
	android:layout_width="fill_parent" android:layout_height="fill_parent"
	xmlns:android="//schemas.android.com/apk/res/android">

	// horizontal and vertical Scrollview
	<ScrollView android:id="@+id/ScrollView01"
		android:layout_height="135px" android:layout_width="wrap_content"
		android:scrollbars="horizontal|vertical">

		// HorizontalScrollview
		<HorizontalScrollView android:id="@+id/HorizontalScrollView01"
			android:layout_height="fill_parent" android:layout_width="wrap_content">

			<LinearLayout android:id="@+id/LinearLayout02"
				android:layout_width="wrap_content" android:orientation="vertical"
				android:layout_height="fill_parent">
				<LinearLayout android:orientation="horizontal"
					android:layout_width="fill_parent" android:layout_height="fill_parent"
					android:layout_weight="1">
					<TextView android:text="red" android:gravity="center_horizontal"
						android:background="#aa0000" android:layout_width="200px"
						android:layout_height="fill_parent" android:layout_weight="1" />
					<TextView android:text="green" android:gravity="center_horizontal"
						android:background="#00aa00" android:layout_width="200px"
						android:layout_height="fill_parent" android:layout_weight="1" />
					<TextView android:text="blue" android:gravity="center_horizontal"
						android:background="#0000aa" android:layout_width="200px"
						android:layout_height="fill_parent" android:layout_weight="1" />
					<TextView android:text="yellow" android:gravity="center_horizontal"
						android:background="#aaaa00" android:layout_width="200px"
						android:layout_height="fill_parent" android:layout_weight="1" />
				</LinearLayout>

				<LinearLayout android:orientation="vertical"
					android:layout_width="fill_parent" android:layout_height="fill_parent"
					android:layout_weight="1">
					<TextView android:text="row one" android:textSize="15pt"
						android:layout_width="fill_parent" android:layout_height="wrap_content"
						android:layout_weight="1" />
					<TextView android:text="row two" android:textSize="15pt"
						android:layout_width="fill_parent" android:layout_height="wrap_content"
						android:layout_weight="1" />
					<TextView android:text="row three" android:textSize="15pt"
						android:layout_width="fill_parent" android:layout_height="wrap_content"
						android:layout_weight="1" />
					<TextView android:text="row four" android:textSize="15pt"
						android:layout_width="fill_parent" android:layout_height="wrap_content"
						android:layout_weight="1" />
				</LinearLayout>


			</LinearLayout>
		</HorizontalScrollView>
	</ScrollView>
</LinearLayout>



Other sample


<?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:id="@+id/layout"
    android:orientation="vertical" >

    <HorizontalScrollView
        android:id="@+id/horizontalScrollView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <LinearLayout
            android:id="@+id/linearLayout1"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="horizontal" >
        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Hello world! First TextView" />

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Large Text"
            android:textAppearance="?android:attr/textAppearanceLarge" />

        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Medium Text"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        </LinearLayout>



    </HorizontalScrollView>

</LinearLayout>

171

WebView change height Android Example | webview-change-height-android-example


The Android WebView changing the height according to text size.
If you need to change the height to a minimum try this source:

//public void loadDataWithBaseURL (String baseUrl, String data, String mimeType, String encoding, String historyUrl) 
WebView _webView; // findById(.....
String entryContent = "";
 _webView.loadDataWithBaseURL(
	"blabol",//  javascript i styly
	entryContent, null,
	"utf-8", null
);



Editace: 2013-12-09 13:10:42
Počet článků v kategorii: 397
Url:draw-text-drawtext-android-basic-example

AD
11 Share
Share
Tweet