Question

I'm trying to put admob ad at the top of my app but the normal text needs to stay centered in the middle... with the below code only one of the components are displayed..

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:myapp="http://schemas.android.com/apk/res/test.testpkg"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_gravity="center"
    android:gravity="center"
    android:background="@drawable/background"
    android:padding = "10dip" >

    <com.admob.android.ads.AdView
        android:id="@+id/ad" 
        android:gravity="center"
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"
        myapp:backgroundColor="#000000"
        myapp:primaryTextColor="#FFFFFF"
        myapp:secondaryTextColor="#CCCCCC" />

    <test.testpkg.CustomTextView android:id="@+id/landscapeText"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"
        android:textColor = "#000"
        android:textSize="40sp"
        android:shadowColor="#FFF"
        android:shadowDx="1.2"
        android:shadowDy="1.2"
        android:shadowRadius="1.2"
        android:gravity="center_vertical"
        android:text ="Test" />
</LinearLayout>
Was it helpful?

Solution

LinearLayout has an additional attribute android:orientation (doc). The default value ist "horizontal", but you need "vertical", because at the moment the CustomTextView gets rendered right of the AdView and outside of the screen.

Additional hint: if you want your CustomTextView really in den middle of the screen, you should use RelativeLayout instead of LinearLayout and add the attribut android:layout_centerInParent="true" -> gets displayed in the middle.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top