How to create android app with app widget in single application

Create and configure widget To register a widget you create a BroadcastReceiver with an intent filter for the android.appwidget.action.APPWIDGET_UPDATE action. <receiver android:icon=”@drawable/icon” android:label=”Example Widget” android:name=”MyWidgetProvider” > <intent-filter > <action android:name=”android.appwidget.action.APPWIDGET_UPDATE” /> </intent-filter> <meta-data android:name=”android.appwidget.provider” android:resource=”@xml/widget_info” /> </receiver> You also specify the meta-data for the widget via the android:name=”android.appwidget.provider attribute. The configuration file referred by this … Read more

Android getMeasuredHeight returns wrong values !

You’re calling measure incorrectly. measure takes MeasureSpec values which are specially packed by MeasureSpec.makeMeasureSpec. measure ignores LayoutParams. The parent doing the measuring is expected to create a MeasureSpec based on its own measurement and layout strategy and the child’s LayoutParams. If you want to measure the way that WRAP_CONTENT usually works in most layouts, call … Read more

get layout height and width at run time android

Suppose I have to get a LinearLayout width defined in XML. I have to get reference of it by XML. Define LinearLayout l as instance. l = (LinearLayout)findviewbyid(R.id.l1); ViewTreeObserver observer = l.getViewTreeObserver(); observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() { @Override public void onGlobalLayout() { // TODO Auto-generated method stub init(); l.getViewTreeObserver().removeGlobalOnLayoutListener( this); } }); protected void init() { int … Read more

How to stretch three images across the screen preserving aspect ratio?

Got it working! But as I said above, you need to create your own class. But it is pretty small. I created it with the help of this Bob Lee’s answer in this post: Android: How to stretch an image to the screen width while maintaining aspect ratio? package com.yourpackage.widgets; import android.content.Context; import android.util.AttributeSet; import … Read more