I have created Android layout resource files for landcape mode for all different screen sizes such as, small, large, medium and extra large , however, when I run the app it does not work in landscape mode as half of the buttons, images are missing from the screen.
I have also included the below line in the android Manifest file.
android:configChanges="keyboardHidden|orientation|screenSize"
Please advice how I can make andriod aware of when to use the landscape and portrait mode.
This is happening because you have added android:configChanges="keyboardHidden|orientation|screenSize"
in your manifest which means the orientation changes will not occur hence your landscape layout never gets initialised. By default the android behaviour is that when the mobile is rotated the current activity is destroyed and new one is created.
Remove that line and try
In the java file of an activity this is how you can recognize if you are in a Landscape mode or portrait mode.
int orientation = getResources().getConfiguration().orientation;
if(orientation == Configuration.ORIENTATION_LANDSCAPE) {
//do something
} else {
//do something
}
okay I am giving an example.....i had a imageview in my layout. when I go to portrait mode it is set one image. and when I go to landscape mode it changes to another image.
ImageView headerimage= (ImageView) findViewById( R.id.headerimage);
int orientation = getResources().getConfiguration().orientation;
if(orientation == Configuration.ORIENTATION_LANDSCAPE) {
headerimage.setBackgroundResource(R.drawable.splash_icon_landscape);
} else {
headerimage.setBackgroundResource (R.drawable.splash_icon_portrait);
}
Related
I am trying to handle change orientation. I enforce orientation in Manifest:
android:screenOrientation="landscape"
android:configChanges="orientation|screenSize"
Then in Activity I set onConfigurationChanged, but it doesn't work. It doesn't handle the change orientation. When I don't set orientation in Manifest, everything works perfect, but I need landscape when the activity starts.
#Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
startActivity(
new Intent(GraphActivity.this, MainActivity.class)
.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP));
}
}
Thanks guys
onConfigurationChanged won't be called if you have set fixed orientation in manifest
what if user runs app in portrait? it will start with horizontal layout, then if user still want to be in portrait then he must rotate device to landscape and back again to portrait? your described behavior looks to me like bad UX...
but, answering: there is no "landscape-only-on-start" for screenOrientation... if you really want to program such behavior then you have to use some code, especially setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_HORIZONTAL); method, but probably also some manual orientation calculation (sensor callbacks)
I have a requirement that I have to take a screenshot of the current window in android.
This is the code am using,
View rootView = getWindow().getDecorView().findViewById(android.R.id.content);
View screenView = rootView.getRootView();
screenView.setDrawingCacheEnabled(true);
Bitmap bitmap = Bitmap.createBitmap(screenView.getDrawingCache());
screenView.setDrawingCacheEnabled(false);
by using this I could get the application screen shot, but the status bar contents are missing (bluetooth icon, battery status etc).
How can I take a screenshot of the current Android phone window programmatically (including status bar contents)?
Is it possible?
On Android 5.0+, use the media projection APIs to take a screenshot of the device screen. See this sample app, as the process is somewhat involved.
On older Android devices, there is no support for programmatic screenshots of the device screen.
i am building an android lib with AdMob to use on kony platform. The lib works great for a android phone or for tablets which are in portrait mode by default, but the Ad doesn't display on the galaxy Tab 10.1 (which is a in landscape by default).
i get this error :
Not enough space to show ad. Needs 1280x90 dp, but only has 800x1207 dp.
it seems that Admob get the size in landscape mode instead of the portrait size. (to be clear, portrait being 800x1207 and landscape 1280x800 when a write about it) and i am not sure where does the issue com from
my application is portrait mode only and i use this code to create my banner :
public View onCreateView(Context context) {
adView = new PublisherAdView(context);
adView.setAdUnitId(MY_AD_UNIT_ID);
adView.setAdSizes(AdSize.SMART_BANNER);
/*LayoutParams lparams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
adView.setLayoutParams(lparams);*/
PublisherAdRequest.Builder publisherAdRequestBuilder = new PublisherAdRequest.Builder();
// Optionally populate the ad request builder.
publisherAdRequestBuilder.addTestDevice("XXXXXXX");
adView.loadAd(publisherAdRequestBuilder.build());
return adView;
}
onCreateView is call by the kony platform to display the Ad and I don't really know what's happen on this side. This code works fine for any android phone and tablet which are in portrait mode by default.
i can also display an Ad on the galaxy 10.1 if I change SMART_BANNER by Leaderboard but it's not centered on the Kony app and not as convenient as the smart banner.
I don't know android a lot and might have forgot to check something basic.
is there anything i could try to get the correct size before to investigate if it comes from Kony?
Thanks
Please check your layout for any padding. It just works if you remove any default padding.
Cheers!
My android
My app takes a photo in portrait.
In the gallery I see it OK
but when saved to my server i see it in landscape.
(This happens only on Samsun S2)
I have read it might be connected with exif tags.
I have checked my image file and got
ORIENTATION_ROTATE_90
what does this mean?
I have tried to set it to ORIENTATION_NORAML or ORIENTATION_UNDEFINED but I'm not sure how to see the change?
In the photo gallery i see it in landscape only
(whether taken in portrait or landscape)
I managed to set the attributes as I read the new ones correctly.
but how do I see the change? does this should help my original problem?
ExifInterface exif;
try {
exif = new ExifInterface(imageFilename);
int orientation =
exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
exif.setAttribute(ExifInterface.TAG_ORIENTATION,
String.valueOf(ExifInterface.ORIENTATION_ROTATE_270));
//also tried ExifInterface.ORIENTATION_ROTATE_UNDEFINED)
exif.saveAttributes();
orientation =
exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
boolean b = orientation == Configuration.ORIENTATION_LANDSCAPE;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
how can I fix this?
why is changing the exif tag not enough? and if changing the exif tag does nothing - why do I need to change it in addition to rotation?
My app takes a photo in portrait. In the gallery I see it OK but when saved to my server i see it in landscape.
That is because your server is ignoring the EXIF header.
(This happens only on Samsun S2)
It happens on many more devices than this. It's one of the many things that I patch up for developers in my CWAC-Camera library.
I have checked my image file and got ORIENTATION_ROTATE_90 what does this mean?
It is a message from the camera, to image-viewing apps, saying "plz rotate this 90 degrees when you show it! kthxbye"
I have tried to set it to ORIENTATION_NORAML or ORIENTATION_UNDEFINED but I'm not sure how to see the change?
All that will do is cause your image to be wrong everywhere, if you did nothing else. You need to rotate the image file in addition to dealing with the EXIF tag.
Can we have a different xml for landscape and different xml for portrait orientation?
I am working on a simple app, have few buttons and textviews, the xml looks good in portrait, But with same xml when I check the landscape orientation, design doesn't look good.
Any suggestions are appreciated..
Thank you.
Yes ofcourse.
You will have to create two versions of xml files and put in layout-port and layout-land folder inside res folder.
eg :
res/layout [Portrait Mode; default]
main.xml
res/layout-land [Landscape Mode]
main.xml
You can refer further more on the same at http://developer.android.com/training/basics/supporting-devices/screens.html
If you want to make another layout for landscape then put it in
res -> layout-land folder .
Both the names of the xml are must be same for which is used for portrait and landscape .
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_screen_orientation_app);
if(getResources().getDisplayMetrics().widthPixels>getResources().getDisplayMetrics().
heightPixels)
{
Toast.makeText(this,"Screen switched to Landscape mode",Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(this,"Screen switched to Portrait mode",Toast.LENGTH_SHORT).show();
}
}
you should make a different xml file for landscape orientation. below link can help you
http://developer.android.com/training/basics/supporting-devices/screens.html