I have been googling for a solution, and I only find solutions where FrameLayout or RelativeLayout is used, and I am using LinearLayout.
What I am trying to do is display an image in the foreground saying “please wait” before some things load on the page. And I am trying to have that image be centered, and not shift the other page elements around…so for that I guess I need it in the foreground, right?
How could I do this? Right now I have this:
<ImageView
android:id="@+id/please_wait"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/please_wait"
android:foregroundGravity="center|fill_horizontal" />
But it is not centering the image and isn’t putting it in the foreground.
Here is the whole xml file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<include android:id="@+id/header"
layout="@layout/header"
android:layout_height="wrap_content"
android:layout_width="fill_parent"/>
<ImageView
android:id="@+id/please_wait"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/please_wait"
android:foregroundGravity="center|fill_horizontal"
/>
<TextView
android:id="@+id/problem_loading_prompt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Getting the business(es) you are planning. They are stored in a database that is constantly backed up so you do not lose your work."
/>
<ListView
android:id="@android:id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@+id/label"
android:textSize="17sp">
</ListView>
<Button
android:id="@+id/add_problem_ok"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="@color/light_best_blue"
android:text="Plan a New Business"
android:layout_marginTop ="15dp"
/>
</LinearLayout>
Thanks!
I think that the best way to display “please wait” message is just create Dialog. Here: http://developer.android.com/guide/topics/ui/dialogs.html you have good tutorial how to create a dialog. I think you can use AlertDialog with custom view, or ProgressDialog, because it has beauty spinner.
Dialogs you call from java code, not from xml, so Dialog isn’t strict answer to your question, but I think that it is close to what you want.
If you really want to do something like that in xml, I think you have to use FrameLayout, because it is designed to do something like that. Or you could try use RelativeLayout.
EDIT:
Here is sample code for create AlertDialog with your image:
And here you have xml file named custom.xml:
Of course you can use different layout also.