Forum Xamarin.Forms
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

Showing contents of PCL XAML file and android layout AXML file

Ska11Ska11 USMember ✭✭

I made a blank app in Visual Studio and it comes with PCL and an iOS project and a Android project. The PCL has a MainPage.xaml to which I added some basic elements to display. When I run the app everything is fine and I can see all the elements I added.

Next, I tried to follow this article (accompanying repo is here) to try and implement AdMob ads.

I got it working but now when I launch the app all I see is the ad on top and a white screen. I do not see any of the elements that I have in MainPage.xaml

The android project has a Main.axml file that looks like this
<?xml version="1.0" encoding="utf-8"?>

I set it in MainActivity with SetContentView(Resource.Layout.Main);

I guess I'm a little confused on how to show both MainPage.xaml contents as well as the Main.axml contents. I did not expect Main.axml to have height of the whole page since I used wrap_content for the android:layout_height

Posts

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    Have you built any Xamarin app before? Maybe you should start out with just learning the basics, following tutorials, getting a feel for XAML etc., before adding complications like advertising.

  • Ska11Ska11 USMember ✭✭

    I was curious about Xamarin Forms so I took a Udemy course about it and learned a lot in the last week or so. They didn't cover anything about Android layout files specifically so once I build one by following this AdMob tutorial I got stuck in a situation wasn't sure about - what to do when you have a XAML file with different controls/elements and an Android AXML file. I was expecting that element in AXML file to be short and overlaid over the elements created by the XAML file in PCL.

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    what to do when you have a XAML file with different controls/elements and an Android AXML file.

    You're building Xamarin.Forms - You should only have XAML in the PCL project. You don't use AXML files. The major point of a forms project is that all the layout and logic is in the common (PCL) project and thus shared across all the platforms.

    I was curious about Xamarin Forms so I took a Udemy course about it and learned a lot in the last week or so. They didn't cover anything about Android layout files

    If the course was on Xamarin.Forms - then they shouldn't/wouldn't have gone over anroid AXML files - they aren't for Xamarin.Forms.

    I was expecting that element in AXML file to be short and overlaid over the elements created by the XAML file in PCL.

    Nope. Not even close. This is the problem with just guessing at how complex system works. You need to back up and just work through the Xamarin tutorials until you grasp the architecture and foundation concepts of a Xamarin.Forms solution where 95% or more of your code and markup are shared and platform-agnostic.

    https://developer.xamarin.com/guides/xamarin-forms/getting-started/

    http://www.RedPillXamarin.com

  • Ska11Ska11 USMember ✭✭

    I absolutely agree with all of your points. However, if I want to know more about how ads are implemented I NEED to go into the Android project and work with android specific things - such as the layout files for example.

  • AdamMeaneyAdamMeaney USMember ✭✭✭✭✭

    And that's where you learn about Custom Renderers and Dependency Injection, which are in the Forms Guides.

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    @Ska11 said:
    I absolutely agree with all of your points. However, if I want to know more about how ads are implemented I NEED to go into the Android project and work with android specific things - such as the layout files for example.

    Probably not. You just don't know any other way because you don't know enough about the basics. You can lay native controls on PCL forms.

    If you had only ever seen a VW Beetle - never ever saw an 18 wheeler - you would have all sorts of odd ideas about how you would move cargo on the highways.

    You're trying to figure out how to build a 5 story apartment building without having every designed a simple tool shed. That just doesn't work.

  • Ska11Ska11 USMember ✭✭

    But I don't need an 18 wheeler if all I have is one grocery bag. I'm not trying to make an application like a YouTube for example, but I get your point.

  • WillHampton.1776WillHampton.1776 USMember ✭✭
    edited July 2017

    https://developer.xamarin.com/samples/monodroid/google-services/AdMobExample/

    Take a look at this code, may be of use. This app implements AdMob the Xamarin way

  • Ska11Ska11 USMember ✭✭

    For anyone that might be looking for something similar in the future here is a set of great articles, which is exactly what I was trying to ask here in the first place. Thanks for your replies, they all helped in their own way.

    https://developer.xamarin.com/guides/xamarin-forms/application-fundamentals/custom-renderer/view/#Creating_the_Custom_Control

    Also,

    https://jefdaels.wordpress.com/2017/04/17/xamarin-forms-pcl-adding-uwp-advertising/

Sign In or Register to comment.