splashscreen imageview not displaying images - android

Hi guys i have this splash screen with the layout main.xml which contains an imageview,
here is the main.xml file
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/LinearLayout2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/slide11" />
</LinearLayout>
and here is my splashscreen.class file
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
try {
new Handler().postDelayed(new Runnable() {
public void run()
Intent intent = new Intent(getApplicationContext(),content_activity.class);
startActivity(intent);
Main.this.finish(); } }, 5000);
} catch(Exception e){}
}
#Override
public void onBackPressed() {
super.onBackPressed();
} }
when i try to run this in my emulator all works fine, but when i try to run it in a device through debugging mode i don't get the image specified in the imageView, but i get a white screen for the specified amount of time.any help would be much appreciated.
//edit : i double checked the res/drawable folder and i tried primarily using png and also gave a go using .gif none worked in the device. (device micromax a110)

use this instead of your layout.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/LinearLayout2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#drawable/slide11" >

looks like it was because of the size of the image, when reduced worked !!

Use image as layout background :-
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/LinearLayout2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#drawable/slide11"
>
</LinearLayout>

This can be happening due to issue in the manifest file. Here is an example of my manifest file which has 3 activities and 1 splash screen. Hoping that this helps out.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.foodorder">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.FoodOrder">
<activity android:name=".MainActivity"></activity>
<activity android:name=".Final_activity" />
<activity android:name=".Second_activity" />
<activity
android:name=".SplashActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

Related

How to make application rotate in AVD

This is for a school project, but i didn't understand many parts of this.
I am leaving the handling of the rotation to the system, but after describing 2 layouts (standart and landscape mode)
But the landscape mode layout won't be taken into account when I rotate the screen.
(source: hostingpics.net)
(I have pressed the 4th button, in case it is the issue ...)
The mainactivity extends AppCompatActivity, (Because our teacher told us to), and all I do (for now) in the MainActivity is
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.d(TAG,"Test");
}
then I described 2 LinearLayouts, one in layout/activity_main.xml :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:baselineAligned="false"
android:divider="#drawable/empty_divider_tall"
android:showDividers="middle"
android:background="#color/fl_concrete"
>
<fragment
class="com.example.g20901528.androidproject.fragment.TopFragment"
android:id="#+id/fragment_top"
android:layout_weight="1"
android:layout_height="match_parent"
android:layout_width="match_parent"
/>
<fragment
class="com.example.g20901528.androidproject.fragment.BottomFragment"
android:id="#+id/fragment_bottom"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</LinearLayout>
and another in layout-land/activity-main.xml which is almost the same :
edit : layout-land/activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:baselineAligned="false"
android:divider="#drawable/empty_divider_wide"
android:showDividers="middle"
android:background="#color/fl_concrete"
>
<fragment
class="com.example.g20901528.androidproject.fragment.TopFragment"
android:id="#+id/fragment_top"
android:layout_weight="1"
android:layout_height="match_parent"
android:layout_width="match_parent"
/>
<fragment
class="com.example.g20901528.androidproject.fragment.BottomFragment"
android:id="#+id/fragment_bottom"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</LinearLayout>
I did not change my manifest aside describing the MainActivity :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.g20901528.androidproject">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
My question is : how to make it so the two fragments rotate when i rotate the phone ?
I'm ready to provide any information.
Github Link of the project, if you really need it.
dude your layout xml name is different please change that
layout/activity_main.xml
layout-land/activity-main.xml make it -->
layout-land/activity_main.xml
and run

Splash Screen not properly displayed

Code For splash.xml :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://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"
android:background="#drawable/notice2"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context=".SplashScreen">
</RelativeLayout>
Code For AndroidManifest.xml :
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name="com.kksworld.noticeboard.SplashScreen"
android:label="#string/title_activity_splash_screen"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.kksworld.noticeboard.LoginActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar">
</activity>
<activity
android:name="com.kksworld.noticeboard.Registration"
android:label="#string/title_activity_registration"
android:theme="#style/AppTheme.NoActionBar" />
</application>
`I am trying to add splash screen in my project. But after running the app the screen stops for the time i have set the timer but exact splash screen is not coming. After that everything is coming. Please Help. Thanks.
Code for Splash Activity :
public class SplashScreen extends Activity {
// Splash screen timer
private static int SPLASH_TIME_OUT = 3000;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.content_splash_screen);
new Handler().postDelayed(new Runnable() {
/*
* Showing splash screen with a timer. This will be useful when you
* want to show case your app logo / company
*/
#Override
public void run() {
// This method will be executed once the timer is over
// Start your app main activity
Intent i = new Intent(SplashScreen.this, LoginActivity.class);
startActivity(i);
// close this activity
finish();
}
}, SPLASH_TIME_OUT);
}
}
Try using the bellow code
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="info.androidhive.androidsplashscreentimer"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<!-- Splash screen -->
<activity
android:name="info.androidhive.androidsplashscreentimer.SplashScreen"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.Black.NoTitleBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- Main activity -->
<activity
android:name="info.androidhive.androidsplashscreentimer.MainActivity"
android:label="#string/app_name" >
</activity>
</application>
</manifest>
activity_splash.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/gradient_background" >
<ImageView
android:id="#+id/imgLogo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="#drawable/wwe_logo" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:textSize="12dp"
android:textColor="#454545"
android:gravity="center_horizontal"
android:layout_alignParentBottom="true"
android:text="www.androidhive.info" />
</RelativeLayout>
SplashScreen.java
package info.androidhive.androidsplashscreentimer;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
public class SplashScreen extends Activity {
// Splash screen timer
private static int SPLASH_TIME_OUT = 3000;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
new Handler().postDelayed(new Runnable() {
/*
* Showing splash screen with a timer. This will be useful when you
* want to show case your app logo / company
*/
#Override
public void run() {
// This method will be executed once the timer is over
// Start your app main activity
Intent i = new Intent(SplashScreen.this, MainActivity.class);
startActivity(i);
// close this activity
finish();
}
}, SPLASH_TIME_OUT);
}
}
Splash screens that delay the app should not be used as they interrupt the users in whatever they want to do with your app.
But: There is a way better approach and it is even easier to implement!
Every app needs some time to start and while its starting, most apps only display a white background as this is the default. You can change that however by adding a new style to your themes.xml that sets the windowBackground to any drawable
<style name="YourApp.AppTheme.Splashscreen" parent="YourApplicationsTheme">
<item name="android:windowBackground">#drawable/splashscreen</item>
</style>
You can define the drawable like that if you want a logo on a coloured background:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
android:opacity="opaque">
<item android:drawable="#color/some_color"/>
<item>
<bitmap
android:gravity="center"
android:src="#drawable/some_logo"/>
</item>
</layer-list>
Just add this theme to your <application> in the AndroidManifest.xml and your splash screen is already up and working.
Finally, set your theme back to your normal theme after the startup using
getApplication().setTheme(R.style.YourApplicationsTheme);
to prevent the splash from appearing whenever you switch activities.
All done! A beautiful splash screen without delaying the user.
Android design guidelines are also suggesting that way and you can also see this for reference.
Check your layout files. Make sure you are using the correct layout files. In the java code you have used content_splash_screen.xml, but, you have posted the code for splash.xml.
There are no errors in the code, your code should run fine.

Error Binary XML file line #2: Error inflating class on android programming

I have an android program with 2 layouts. The first layout is Login. When the login is started first, I have no problem. When I try to change in AndroidManifest from login to splash layout, I got an error. The error is like the title of this posts.
In this android manifest, I change my code from :
<?xml version="1.0" encoding="utf-8"?>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"
>
<activity
android:name=".Login"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
to :
<?xml version="1.0" encoding="utf-8"?>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"
>
<activity
android:name=".Splash"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Here is the layout for login:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:orientation="vertical"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin" tools:context=".Login">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Your total is 0"
android:textSize="45dp"
android:gravity="center"
android:id="#+id/tvDisplay"
/>
<Button
android:layout_width="250dp"
android:layout_height="100dp"
android:text="Add One"
android:gravity="center"
android:layout_gravity="center"
android:id="#+id/bAdd"
android:textSize="20dp"/>
<Button
android:layout_width="250dp"
android:layout_height="100dp"
android:text="Substract One"
android:gravity="center"
android:layout_gravity="center"
android:id="#+id/bSub"
android:textSize="20dp"/>
And here the layout of splash:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:background="#drawable/sertifikat"
tools:context=".Splash"></LinearLayout>
And structure of my code :
Log in logcat:
Here splash.java
How can I fix my code?
Hey You missed some small things
Here is a small example from your code
on Github that i wrote
This is running example of your code
Other than the ending tags
The <intent-filter>
should only be one
most probably the problem lies in your #drawable
as well as look at these tutorials they are great
http://www.androidhive.info/2013/07/how-to-implement-android-splash-screen-2/
Obviously,you have lost a character '/' in the splash layout at the end.
You are missing the closing tag of your LinearLayout in splash.xml. Add </LinearLayout> to the end of the file. You also might want to consider using an ImageView with android:scaleType="centerCrop" instead of using a LinearLayout with a background. Using android:background will stretch to fit the size of the screen, which can give a different aspect ratio on different devices, whereas an ImageView will scale it to maintain the aspect ratio (depending on the scaleType).
Also, a LinearLayout is not appropriate for a single image, since it is meant to be a container for other views.
For better performance I recommend you to follow this :
http://www.cutehacks.com/blog/2014/01/13/splash-screens
If you use an high end device you won't see a big difference, but for common devices you will see an huge improvement

Android setContentView uses wrong layout file

My bare-bones test app sets the orientation to landscape on start up. It has a layout and layout-port directory. There is a simple layout file in each directory. They contain a textview with text set to either "Landscape" or "Portrait".
In my test I start the app on a tablet tipped into portrait. With this code, I would expect the layout from /layout/my_layout.xml to be used, but /layout-port/my_layout.xml is used instead. I've also tried making a /layout-land directory but still no luck.
From my main activity:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Start app with tablet in portrait orientation
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
int o = this.getRequestedOrientation();
// o is 0, indicating landscape. Display shifted to landscape
setContentView(R.layout.my_layout);
// layout-port/my_layout.xml is loaded. INCORRECT I think
}
/layout/my_layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ff000000">
<TextView
android:id="#+id/tvLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Landscape"
android:textSize="50sp"
android:textColor="#ffffffff"/>
</LinearLayout>
/layout-port/my_layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ff000000">
<TextView
android:id="#+id/tvLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Portrait"
android:textSize="50sp"
android:textColor="#ffffffff"/>
</LinearLayout>
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mytest"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="16" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.mytest.ActivityMain"
android:configChanges="keyboardHidden|orientation|screenSize"
android:label="#string/app_name"
android:windowSoftInputMode="stateHidden|adjustPan" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Change /res/layout/my_layout.xml to /res/layout-land/my_layout.xml
Note: I added the suffix -land
Your have to remove option "orientation" in manifest:
android:configChanges="screenSize|orientation|keyboardHidden"
Because this option says you handle it by yourself...
Good explanation here:

The emulator isn't showing the XML contents

I have been reading Google's android tutorial and I got a problem... In the tutorial they explain the XML elements (EditText and Button) and in the end they say how to tun the program to see the button + the text field.
The problem is, that the emulator doesn't show them.. just a black screen.
I even tried adding this line to the onCreate function -
System.out.println("Hello World!");
but still the emulator is showing only black screen..
Here's the .java main file - http://pastebin.com/G5J9YjNe
And the XML files (I mentioned what code is what file) - http://pastebin.com/VnRwAfMW
What should I do?
Thanks a lot for everyone who will help!
System.out.println("Hello World!");
does not print any thing on screen. it can seen on Consol. i tried below code and working fine for me.
// Main Activity
public class MainActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.kuchbhi);
System.out.println("Hello World!");
}
Layout /.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<EditText android:id="#+id/text_message"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="enter text" />
<Button android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Send" />
</LinearLayout>
Manifest file ..
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.test"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name="MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
try this code and let me know what u see.
I tried your source code and it is working fine for me. see screen

Categories

Resources