Declaring RelativeLayout footer in code

nathan2005

New Member
I tried almost everything.I decided that putting ads in XML isn't safe way so i wanted to do that through code. This is how i made this in XML\[code\]<?xml version="1.0" encoding="utf-8"?><RelativeLayout 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"> <com.google.ads.AdView android:id="@+id/adViewContactsList" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" ads:adUnitId="My Unit id" ads:adSize="BANNER" ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID" ads:loadAdOnCreate="true"/> <FrameLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:layout_weight="200" android:layout_above="@id/adViewContactsList"> <ListView android:id="@+id/contactsList" android:layout_width="fill_parent" android:layout_height="fill_parent" android:cacheColorHint="#0000" android:listSelector="@drawable/listview_background_pressed" android:divider="@color/convListSep" android:dividerHeight="0.5dp" android:fadingEdge="none" android:scrollingCache="false" > </ListView> <View android:layout_width="fill_parent" android:layout_height="5dp" android:background="@drawable/background_shadow" /> </FrameLayout></RelativeLayout>\[/code\]Every time i tried to make footer for Ads through it works like FrameLayout only (it covers bottom part of list). This is my code (of course after deleting ads in XML)\[code\]adView = new AdView(this, AdSize.BANNER, GateSMSApp.AD_ID);RelativeLayout layout = (RelativeLayout)findViewById(R.id.layoutContactsList);RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);adView.setLayoutParams(params);AdRequest adRequest = new AdRequest();adRequest.addTestDevice(AdRequest.TEST_EMULATOR);adView.loadAd(adRequest);layout.addView(adView);RelativeLayout.LayoutParams frameLayoutParams = (RelativeLayout.LayoutParams) findViewById(R.id.frameLayoutList).getLayoutParams();FrameLayout frameList = (FrameLayout) findViewById(R.id.frameLayoutList);RelativeLayout.LayoutParams viewParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.FILL_PARENT);viewParams.addRule(RelativeLayout.ABOVE, adView.getId());frameList.setLayoutParams(viewParams);\[/code\]Hah, got it.The code is ok, but id of view created in code is -1 or something different.Point is all i had to do is change id of adView:\[code\]adView.setId(123123);\[/code\]
 
Back
Top