How to draw a combination of views - view

I wanted to have a custom layout where I would have gallery on top, then below it to have a simple widget to show the picture when it is chosen from the gallery. I could not figure out how to compose that main.xml to achieve it, your advice will be greatly appreciated.
The gallery layout xml is straight from the google tutorial and is working. How do I modify it to achieve the above?
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
HT

ok, I have figured it out for myself, for others who may need this in the future, the main.xml looks below:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Gallery xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/gallery"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<ImageView
android:id="#+id/image1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/gallery"
android:layout_alignParentRight="true"
android:layout_marginLeft="10dip"
/></RelativeLayout>

Related

Do I need to surround a <TableView> with a <StackLayout> in a <ContentPage>

I am working on an application where the developer has a <ContentPage> with a <TableView> inside. Is this needed / normal practice? I am trying to work out why the developer did this.
The developer added a element surrounding the <TableView>
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
Title="Network">
<ContentPage.Content>
<StackLayout>
<TableView>
...
</TableView>
</StackLayout>
</ContentPage.Content>
</ContentPage>
A ContentPage can only have a single child element. It's not uncommon to include some sort of Layout container as the child, so multiple child elements can be added to the page. However, in cases like this where there is really only a single child it's probably unnecessary.

Custom Attribute of Integer on Custom View

I'm having a few problems creating an integer attribute.
So, as background. I have got a custom canvas view. I have already successfully created a custom string attribute on that. The axml looks like this:
<turbineApp.droid.infrastructure.customViews.TurbineMapCanvas
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/VicMapCanvas"
custom:mapName="VIC"
/>
And the attribute comes from attrs.xml:
<resources>
<declare-styleable name="CustomCanvasView">
<attr name="mapName" format="string" />
</declare-styleable>
</resources>
I was hoping to add an integer attribute. So, I added the following as an element in attrs.xml:
<attr name="originY" format="integer" />
But now the project won't build. At all. With a fail message that the Resources class never got built.
I've unblocked myself by just making it a string and parsing the string in the code. But why will an integer not work? Have the good people at Xamarin not implemented that yet?
Thanks

How to add a loader to a page till I get the data in the background from API in xamarin android MVVM/mono

I am able to get the data from the API which I am using it to bind the data in different ways but when getting the data is going slow, black screen is displayed for some time and then the data is getting loaded so I was trying to rectify that and make the data getting in background(async await) and then bind that to the view when the data is available locally.
How to do that?
Well basic idea is to use ActivityIndicator view which basically is a loading control in each platform. How you use it thought is different in different cases. I personally wrap content of the page in a grid like this:
<ContentPage xmlns:a="">
<Grid>
<ActivityIndicator IsRunning="True" IsVisible="{Binding IsBusy}"/>
<[The original page content]>
</Grid>
</ContentPage>
Then you create a Boolean property named IsBusy in your view model and set it to true when loading content and false after you are done.
-- Edit --
Sorry I didn't notice the original question was about Android and not forms. I will let the previous answer remain here in case anyone wanted to know about Forms solution.
So in Android the quivalant is ProgressDialog. I know you can use it like this:
ProgressDialog mDialog = new ProgressDialog(getApplicationContext());
mDialog.setMessage("Please wait...");
mDialog.setCancelable(false);
mDialog.show();
You put this code after starting you web call in another thread.
There might be better ways so search for the ProgressDialog and you will find them.
If you want to use ProgressDialog with MvvmCross (I see that tag under the topic) you may read an article by Stuart
Follow this sample layout skeleton for those screens where you need to show the activity indicator (Loader):
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/white"
android:id="#+id/parent_layout">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="#+id/txt1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="Text 1"
android:textSize="18dp"
android:textColor="#android:color/black"
android:paddingTop="20dp" />
<TextView
android:id="#+id/txt2"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="Text 2"
android:textSize="18dp"
android:textColor="#android:color/black"
android:paddingTop="20dp" />
</LinearLayout>
<FrameLayout
android:id="#+id/frame_layout"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_centerInParent="true"
android:background="#drawable/loader"
android:visibility="invisible">
<ProgressBar
android:id="#+id/progress_bar"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="center"
android:indeterminate="true"/>
</FrameLayout>
</RelativeLayout>
Accordingly you need to control the FrameLayout from it's id containing the progress bar from your code end either in activity or if you are using fragment to make it visible during the service call and set the visibility to invisible once you received the response.

MvvmCross android binding to fragment

is there any way to bind in layout directly to custom fragment?
ie:
<fragment android:id="#+id/AwesomeFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
local:MvxBind="CustomTarget PropertyInVM;" class="My.Awesome.Fragment" />
CustomTarget is CustomTargetBinding
So how you can do this:
create custom control with properties you need
create target bindings
place custom control into layout instead of your fragment
bind from layout

How to make Firefox extension auto install in nav bar?

I'm working on a Firefox extension. I'd like to make it auto-install in the far right position on the nav bar when a user installs it. As it stands, a user has to go to View > Toolbars > Customize... and drag the extension to the nav bar once it's installed. I'd like to eliminate this step.
The extension is here: http://madan.org/tickertool
The XUL for my extension looks basically like this and it overlays browser.xul:
<overlay id="my-ext-overlay" ... >
<toolbarpalette id="BrowserToolbarPalette">
<toolbaritem id="my-ext-container" ... >
<toolbarbutton id="my-ext-customize-image" ... />
<textbox id="my-ext-textbox" ... />
<hbox id="my-ext-buttons">
<image id="my-ext-button1" ... />
<image id="my-ext-button2" ... />
<image id="my-ext-button3" ... />
</hbox>
</toolbaritem>
</toolbarpalette>
</overlay>
I've seen code here ( https://developer.mozilla.org/en/Code_snippets/Toolbar ) that supposedly does what I'm looking for, but this code is if your extension is just a single button and I can't get it to work for me. The answer to my question is likely some modification of this code, but I haven't figured it out.
I think I got it. It's basically spelled out in the link I mentioned in the original post. I'm not sure why I thought there was more to it than that.

Resources