Bitmap get Bitmap from resource Android example
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);
396LW NO topic_id
AD
Další témata ....(Topics)
// in AndroidManifest.xml
<Activity
android:screenOrientation="portrait" // or landscape
// in MyActivity.java
boolean mbOrientacionLandscape = false;
int nOrientation = getResources().getConfiguration().orientation;
if(mbOrientacionLandscape==true){
getResources().getConfiguration();
if(nOrientation != Configuration.ORIENTATION_LANDSCAPE)
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
else{
if(nOrientation != Configuration.ORIENTATION_PORTRAIT)
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
If you create a button or view programmatically with OnClickListener you can set a tag key before button in parent layout is added.
And get correct button by this tag getTag() instead getId() in OnClickListener etc.
And get correct button by this tag getTag() instead getId() in OnClickListener etc.
Button button = new Button(getApplicationContext());
int idOfButton = button.getId(); // return -1
button.setTag("my_button");
String sTag = (String) button.getTag(); // return "my_button"
Definition of ListView in layout main.xml file Android example
Code in Main.java ListView example source code Java Android
<ListView android:id="@+id/idListView"
android:background="#7700CC00"
android:layout_height="wrap_content"
android:layout_width="fill_parent" />
Code in Main.java ListView example source code Java Android
public class Main extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ListView mlistView = (ListView) findViewById(R.id.idListView);
mlistView.setAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1,
new String[] {"Game", "Help", "Home site"}));
mlistView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// When clicked, show a toast with the TextView text Game, Help, Home
Toast.makeText(getApplicationContext(), ((TextView) view).getText(),
Toast.LENGTH_SHORT).show();
}
});
}
}
Hide module - open dialog: File > Project Structure Ctrl + Alt + Shift + S
Hide module: in opened Dialog select module which will hidden and click on minus (left upper corner)
If module is hidden, you can permanetly delete module from disk. But if you want using module in future, copy module into other folder (not into AndroidProjects folder and his subbfolders) and delete module permanetly from project and disc. Right mouse click on module and select from menu Delete.
If you want import the backup copy to project, use: File>New>Import mudule


Hide module: in opened Dialog select module which will hidden and click on minus (left upper corner)

If module is hidden, you can permanetly delete module from disk. But if you want using module in future, copy module into other folder (not into AndroidProjects folder and his subbfolders) and delete module permanetly from project and disc. Right mouse click on module and select from menu Delete.

If you want import the backup copy to project, use: File>New>Import mudule

1.) check your xml files in res/layout folder if contain errors or warnings, repair this
2.) try comment import R in Activity file
// import com.mysite.packagename.R;
3.) every clean and rebuild project
2.) try comment import R in Activity file
// import com.mysite.packagename.R;
3.) every clean and rebuild project
Editace: 2013-12-09 13:12:32
Počet článků v kategorii: 396
Url:bitmap-get-bitmap-from-resource-android-example