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.

Scroll to certain position on application Android example code


AD MOB

ScrollTo(), getTop(), getBottom(), getLeft(), getRight(), ScrollView, LinearLayout Android Java xml example.
How get position of a View.
MainClass.java

/*
public void scrollTo (int x, int y) 
Since: API Level 1 
Set the scrolled position of your view. This will cause a call to onScrollChanged(int, int, int, int) and the view will be invalidated. 

This version also clamps the scrolling to the bounds of our child.

Parameters
x  the x position to scroll to 
y  the y position to scroll to  
  */

// sroll to top of hscrollViewMain
ScrollView hscrollViewMain = (ScrollView)findViewById(R.id.scrollViewMain);
hscrollViewMain.scrollTo(0, 0); // scroll to application top

// get position of a View
EditText hEdit = (EditText)findViewById(R.id.username_edit);
int nY_Pos = hEdit.getTop(); // getBottom(); X_pos  getLeft(); getRight();
// scroll to top of hEdit
hscrollViewMain.scrollTo(0,nY_Pos); 


main.xml


<LinearLayout
    xmlns:android="//schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
    <ScrollView
        android:id="@*id/scrollViewMain"
        android:layout_width="fill_parent"
        android:layout_height="0dip"
        android:layout_weight="1">
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:orientation="vertical"
            android:paddingTop="5dip"
            android:paddingBottom="13dip"
            android:paddingLeft="20dip"
            android:paddingRight="20dip">
            <TextView
                android:id="@+id/message"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginBottom="5dip" />
            <TextView
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:textStyle="bold"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/login_activity_username_label" />
            <EditText
                android:id="@+id/username_edit"
                android:singleLine="true"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:minWidth="250dip"
                android:scrollHorizontally="true"
                android:capitalize="none"
                android:autoText="false"
                android:inputType="textEmailAddress" />
        </LinearLayout>
    </ScrollView>

</LinearLayout>

397LW NO topic_id




AD

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


266

Change icon set Android developers example | change-icon-set-android-developers


How to quickly change all icon set in .apk project with Eclipse:

Right click on project in folder tree
Select New - Ohter

eclipse-icon-set-create-android-project

In open wizard dialog select Android Icon Set
eclipse-icon-set-create-android-project

Set Icon set name:
eclipse-icon-set-create-android-project

Open some large icon for your project for example 512x512 px and wizard will make all set of icons from one largest icon:
eclipse-icon-set-create-android-project

Wizard will create all set of icons from this one largest icon.
Click on finish button:
eclipse-icon-set-create-android-project
225

Eclipse custom skin GUI color theme | eclipse-custom-skin-gui-color


Eclipse make own color of toolbars, windows, status bar etc.
https://github.com/jeeeyul/eclipse-themes/wiki/Alternative-Install

eclipse-custom-skin-gui-2.jpg

eclipse-custom-skin-gui.png
20

How set gray text to EditText Android example | how-set-gray-text-to-edittext-android-example


Example source code for Android development. How set gray text to EditText when EditText is blank.
Hint text to display when the text is empty.
In layout/main.xml insert to EditText row Attribute Name android:hint="Some text"


<EditText
        android:id="@+id/myEdit" 
	android:layout_height="wrap_content" android:layout_width="fill_parent"
        android:hint="Some text"
	android:singleLine="true"
</EditText>	



Programatically you can use method setHint:


// setHint(CharSequence hint) example
(EditText)findViewById(R.id.myEdit).setHint("My text");
// or int resId as method setHint(int resId) 
EditText myEdit = findViewById(R.id.myEdit);
myEdit.setHint(R.string.app_name);



257

Two boolean as one parameter value in function Java | two-boolean-as-one-parameter-value-in-function-java



boolean fc(boolean b) {
	return b;
}// end fc
		boolean bA = true;
		boolean bB = true;
		boolean bC = bA || bB; // true

		bA = true;
		bB = false;
		bC = bA || bB; // true

		bA = false;
		bB = true;
		bC = bA || bB; // true

		bA = false;
		bB = false;
		bC = bA || bB; // false
		
			if(!fc(bB||bA))
			System.out.println("false"); // false
                        else 
			System.out.println("true"); 


239

Admob ads not visible on emulator Android 4.1 | admob-ads-not-visible-on-emulator-android-4-1


If you using GoogleAdMobAdsSdk-4.0.4.jar in your project and set android:targetSdkVersion="17" in AndroidManifest.xml , ads will not visible on emulator with Android 4.0.3 or 4.1.
You have to set as android:targetSdkVersion="17"


<uses-sdk android:minSdkVersion="4" 
        android:targetSdkVersion="17" />


Update project.properties file - row with target to 17:

# Project target.
target=android-17


Editace: 2011-09-20 15:29:14
Počet článků v kategorii: 397
Url:scroll-to-certain-position-on-application-android-example-code

AD
11 Share
Share
Tweet