开发者

android xml put component on top with layout_gravity="center"

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" e开发者_JAVA百科ncoding="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>


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜