I Have been looking around this for a while now and could not find solution;
When you create ProgressDialog, the Main View is turned to grey and loses focus,What I want to do is to keep an element from the Main View focused (lets say Admob) and keep it usable while the ProgressDialog is shown
UPDATE : CODE !
View mainview = LayoutInflater.from(MainAct).inflate(R.layout.activity_main, null);
View adView = mainview.findViewById(R.id.adView);
mProgress = new ProgressDialog(MainAct);
mProgress.setMessage("Downloading...");
mProgress.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
mProgress.setCancelable(false);
mProgress.setCanceledOnTouchOutside(false);
mProgress.show();
adView.requestFocus();
it seems like using reaquestFocus doesn't work and is only intended for form elements, not bringing elements on TOP
UPDATE 2:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/linlaHeaderProgress"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:orientation="horizontal"
android:visibility="gone" >
<ProgressBar
android:id="#+id/pbHeaderProgress"
style="#style/Spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="2dp" >
</ProgressBar>
<TextView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:gravity="left|center"
android:padding="2dp"
android:text="Loading...."
android:textColor="#F1F1F1"
android:textSize="20sp" >
</TextView>
</LinearLayout>
<ListView
android:id="#+id/list"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:cacheColorHint="#android:color/transparent"
android:divider="#000000"
android:dividerHeight="0dp"
android:fadingEdge="none"
android:persistentDrawingCache="scrolling" >
</ListView>
<TextView
android:id="#android:id/empty"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:padding="10dp"
android:textColor="#f1f1f1"
android:textSize="15sp"
android:textStyle="bold"
android:visibility="gone" >
</TextView>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="bottom|center"
android:orientation="horizontal" >
<com.google.ads.AdView
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adSize="SMART_BANNER"
ads:adUnitId="MY_AD_UNIT_ID"
ads:loadAdOnCreate="true"
ads:testDevices="TEST_EMULATOR, MY_TEST_DEVICE_ID" />
</LinearLayout>
</LinearLayout>
The code above is for a layout that is used almost exclusively in own of my apps. What I do while loading the data is quite simple.
Look at how the ProgressBar is defined in the XML. While still loading data, I change the LinearLayout linlaHeaderProgress to VISIBLE which effectively hides the ListView below it because of the attributes set to it. After I am done loading the data, I change the visibility of the LinearLayout linlaHeaderProgress to GONE. A point to note here is, the Admob XML right at the bottom of the XML, is always visible to the user and can be interacted with anytime before or after the data is loading / done loading.
If you need to show this XML in the form of a Dialog, you can always do so by attaching a Theme to this activity.
Hope some of this helps in your endeavour.
UPDATE
Check these tutorials. These are a few I could find with a quick search for showing a Horizontal ProgressBar. You are using a ProgressDialog.
http://www.techrepublic.com/blog/app-builder/androids-batterymanager-and-progressbar-two-for-one-tutorial/703
http://theandroid.in/example-of-progressbar-in-android/
And finally, use this Google Search to see a few examples of making an activity look like a dialog.
This should help you achieve what your screenshot suggests.
Related
How do I prevent my Android screen from shifting down when a page is view is displayed and receives the first add?
When the view is first displayed the screen is normal, then a ad is displayed and the screen shifts down a few lines.
Here is my code.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="#+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/background3"
android:orientation="vertical" >
<com.google.ads.AdView
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:layout_gravity="top"
ads:adSize="BANNER"
ads:adUnitId="xxxxxxxxxx"
android:gravity="center"
ads:loadAdOnCreate="true" >
</com.google.ads.AdView>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_marginTop="34dp" >
<EditText
android:id="#+id/editText1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1" />
<Button
android:id="#+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="3"
android:text="Start" />
</TableRow>
</LinearLayout>
TIA, Trey
I don't have much experience with the ads. But from strictly a View standpoint it seems like what is happening is that the adView is set to View.GONE before it loads. Which means that its space is ignored when placing the other views into the parent.
I don't know for sure how you could get it to not do that. But I would try explicitly setting it to android:visibility="invisible" in your xml, then in your java you'll have to make it visible after it has loaded. "invisible" is like gone, but it tells the parent to respect the space that you will take up when you are visible.
Perhaps the loadOnCreate attribute causes the behavior you are seeing? Might also be worth trying it without that and just load it manually in your onCreate.
I am trying to layout a home automation app. The top part of the screen will be custom status text (Garage door is OPEN, System is DISARMED, etc). Under the status text there will be a refresh link/button/list item. Something that the user can click on to refresh the status text. At the bottom will be a listview that will be links to other pages and links to actions such as "Security Page", or "Close Garage Door", etc. My question is, how do I configure the layout? I have tried several LinearLayouts, RelativeLayouts, nested layouts, etc, and none have worked so far.
Here is my main.xml as of now:
<?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">
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/statustext">
</TextView>
</LinearLayout>
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/refresh">
</TextView>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:gravity="center_horizontal"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<ListView
android:layout_width="fill_parent"
android:id="#android:id/list"
android:layout_height="wrap_content">
</ListView>
</LinearLayout>
</LinearLayout>
The refresh link could just be an item of the listview, but I would like to style it differently so it stands out, such as a different color font or background. Or it could be a button. But it needs to be between the statustext and itemlist. And everything should scroll as one unit.
Is this possible?
Is this works?
<?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">
<ScrollView android:id="#+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:gravity="center|center_vertical"
android:orientation="vertical" android:layout_height="fill_parent" android:layout_width="fill_parent">
<TextView
android:gravity="center_horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="status"
android:id="#+id/statustext">
</TextView>
<TextView
android:gravity="center_horizontal"
android:layout_height="wrap_content"
android:text="refresh"
android:id="#+id/refresh" android:layout_width="fill_parent" android:layout_gravity="fill_horizontal">
</TextView>
<ListView
android:gravity="center_horizontal"
android:layout_width="fill_parent"
android:id="#android:id/list"
android:layout_height="wrap_content">
</ListView>
</LinearLayout>
</ScrollView>
</LinearLayout>
If you want to have a scroll bar, use ScrollView to warp all sub-items. But ScrollView it self can host only one direct child so you'll need to wrap them all with a LinearLayout which has everything you want inside.
Add you status text content to listheaderview.here is the link for that.
Android listview with header and footer buttons
This way the whole list ll be scrolled with your status text.
Hi all,
I'm a newbie to Android and having problems displaying items using a Linear layout and wondering if anyone can help me. The item list and pictures display fine but the textbox and search button are displayed for each item rather than getting displayed once. My code looks like:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1">
<ImageView
android:id="#+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/icon"/>
<TextView
android:id="#+id/selection"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/searchHeader"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/searchItem"/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/search"
android:onClick="Search"/>
</LinearLayout>
</LinearLayout>
With this XML you should only see exactly one imageview and not a list of images as you discribed. Do you alter this layout programmatically in order do display various images? Maybe there you also add again the items you only want once.
Try moving the textview and search button outside of the linearlayouts they are in.
The button is hidden...why?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="15dp"
android:orientation="vertical">
<ListView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/feed_list"/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="More"
android:id="#+id/feed_more"/>
</LinearLayout>
Assuming that the ListView has enough content to fill up the whole screen, it will since you told it to wrap_content. You can use weights to instruct the ListView to take up as much of the screen as is available, after the button has what it needs:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="15dp"
android:orientation="vertical">
<ListView
android:layout_width="fill_parent"
android:layout_height="0"
android:weight="1"
android:id="#+id/feed_list"/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weight="0"
android:text="More"
android:id="#+id/feed_more"/>
you need to give weight 1 to the list view. then your button will be visible. try it.
I am doing a simple chat application and I want to show balloons similar to the iphone's sms app.
So I am doing an Activity with a ListView with a certain layout.
This are my layouts:
/* Activity Layout */
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ListView android:id="#+id/chat_log"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stackFromBottom="true"
android:layout_marginTop="50dp"
android:transcriptMode="alwaysScroll"
android:layout_weight="1"
android:cacheColorHint="#00000000"
android:clickable="false"
/>
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<EditText android:id="#+id/chat_input_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="bottom"
/>
<Button android:id="#+id/chat_send_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/chat_send_button"
/>
</LinearLayout>
</LinearLayout>
Other:
/* Row Layout */
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/userprofile_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/chat_ballon_left" >
<TextView
android:id="#+id/chat_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="2dp"
android:text="haasdasdasdasdasdasdasdoo" />
</FrameLayout>
Here's the result.
My issues:
The gray line which I would like to remove.
Text is not using the whole space.
Somehow even thought I've added android:clickable="false" the balloons are clickable.
The FrameLayout is unnecessary, so use the TextView as a root element (with the chat_ballon_left background of course). Set the width to match_parent so that the text takes the whole space.
BTW nice baloons, don't forget to have hdpi versions too :)