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.

How get Drawable Android example


AD MOB

InputStream, getResources(),openRawResource()

 java.io.InputStream is;
is = context.getResources().openRawResource(R.drawable.my_image);

Drawable mDrawable = context.getResources().getDrawable(R.drawable.button);
mDrawable.setBounds(150, 20, 300, 100);


Drawable[] mDrawables;
int[] resIDs = new int[] {
                R.drawable.btn_ok,
                R.drawable.btn_storno,
                R.drawable.btn_help
            };
            mDrawables = new Drawable[resIDs.length];
            Drawable prev = mDrawable;
            for (int i = 0; i < resIDs.length; i++) {
                mDrawables[i] = context.getResources().getDrawable(resIDs[i]);
                mDrawables[i].setDither(true);
                addToTheRight(mDrawables[i], prev);
                prev = mDrawables[i];
            }



397LW NO topic_id




AD

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


311

findViewById in onCreate returns NULL when using Fragment | findviewbyid-in-oncreate-returns-null-when-using-fragment


Call findViewById from onCreateView

public class MainActivity extends ActionBarActivity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		if (savedInstanceState == null) {
			getSupportFragmentManager().beginTransaction()
					.add(R.id.containerMoje, new PlaceholderFragment()).commit();
		}
		
	}


	/**
	 * A placeholder fragment containing a simple view.
	 */
	public static class PlaceholderFragment extends Fragment {
		public PlaceholderFragment() {
		}

		@Override
		public View onCreateView(LayoutInflater inflater, ViewGroup container,
				Bundle savedInstanceState) {
			View rootView = inflater.inflate(R.layout.fragment_main, container,
					false);
			if (container == null) {
		        return null;
		    }


			 TextView mText;
			mText = (TextView)rootView.findViewById(R.id.idText);
			mText.setText("Hello from fragment_main");

			return rootView;
		}
	}
}




res\layout
activity_main.xml

<FrameLayout xmlns:android="//schemas.android.com/apk/res/android"
    xmlns:tools="//schemas.android.com/tools"
    android:id="@+id/containerMoje"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="cz.okhelp.autoskola.MainActivity"
    tools:ignore="MergeRootFrame" />



fragment_main.xml

<RelativeLayout xmlns:android="//schemas.android.com/apk/res/android"
    xmlns:tools="//schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="cz.okhelp.autoskola.MainActivity$PlaceholderFragment" >

    <TextView
        android:id="@+id/idText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />

</RelativeLayout>
328

Screen size density independent pixel resolution | screen-size-density-independent-pixel-resolution


Terms Screen size, density, density independent pixel, resolution as a picture - pictogram.
mobile-phone-screen-resolution-terms

Test your knowledge
Q: How to find out the phone screen size?
A: (By length of display diagonale in inch -  Not to measure a diagonal of device!!!)

Q: What resolution has 720 x 1280 display?
A: (921600 pixels)

Q: What does it mean "240 dpi" screen density?
A: (Display have density 240 x 240  dots - "Tri-color LED etc." - per every physical (real) square inch. If you have icon 240x240 pixels, this will just occupy an area of one square inch on the display.)

Q: Phone have screen density 240 dpi. Image for 160 dpi screen density have size 128x 128 pixels. What will be the size of the image for 240 dpi screen density?
A: (Calculate the virtual pixels size.   128 * (240/160)  =  192.  You have to resize image to new size 192 x 192 physical pixels and put into folder drawable-hdpi (high) ~240dpi  for phone with screen density 240 dpi. ) or use density independend pixels 128dp x 128dp.

 

 
75

The Labeled continue statement Java example | the-labeled-continue-statement-java-example


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
*/
281

addPreferencesFromResource Deprecated Android Code Warning | addpreferencesfromresource-deprecated-android-code-warning


Put extends PreferenceFragment API level 11 instead PreferenceActivity

public class SettingsActivity extends PreferenceFragment {
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      addPreferencesFromResource(R.xml.preferences);
  }
}

// or insert suppresswarning
public class SettingsActivity extends PreferenceActivity {
  @SuppressWarnings("deprecation")
	@Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      addPreferencesFromResource(R.xml.preferences);
  }
}

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



Editace: 2013-12-09 13:12:46
Počet článků v kategorii: 397
Url:how-get-drawable-android-example

AD
11 Share
Share
Tweet