Tôi rất mới với Android (như 2 ngày), nhưng tôi có kinh nghiệm với các bộ công cụ bố cục khác. Tôi đang cố gắng đặt một AdView bên dưới một TabHost, và có vẻ như tôi có thể nhận được TabWidget hoặc AdView để hiển thị chính xác, nhưng không bao giờ cả hai.Tôi làm cách nào để có thể sử dụng bao bọc một TabHost có chứa một MapView cũng hiển thị chế độ xem AdMob bên dưới nó?
Thứ nhất, đây là một phiên bản nghệ thuật ASCII về những gì tôi đang cố gắng để hoàn thành:
-------------------------------------------- | Tab 1 | Tab 2 | -------------------------------------------- | MapView when tab 1 is selected | | | | | | | | | | | | | -------------------------------------------- | AdView that stays no matter what tab | --------------------------------------------
Như bạn thấy, tôi đang cố gắng để có được những AdView ngoài các TabWidget hoặc FrameLayout. Tôi muốn nó được dưới toàn bộ nội dung tabhost.
Dưới đây là cách bố trí tôi đã có trước thêm AdView:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:myapp="http://schemas.android.com/apk/res/org.mbs3.android.ufcm"
android:layout_height="fill_parent"
android:layout_width="wrap_content"
>
<TabHost android:id="@+id/tabhost" android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout android:layout_width="fill_parent"
android:id="@+id/home_layout" android:orientation="vertical"
android:layout_height="fill_parent">
<TabWidget android:id="@android:id/tabs"
android:layout_width="fill_parent" android:layout_height="wrap_content" />
<FrameLayout android:id="@android:id/tabcontent"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<RelativeLayout android:id="@+id/emptylayout1"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<!--
programatically added tabs will appear here,
one per activity
-->
</FrameLayout>
</LinearLayout>
</TabHost>
</RelativeLayout>
Bây giờ, tôi đã thử một vài lời khuyên khác nhau để có được những AdView thêm, chẳng hạn như http://www.spencerelliott.ca/blogs/blog-android-menu. Đây là bố cục tốt nhất mà tôi đã đưa ra:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:myapp="http://schemas.android.com/apk/res/org.mbs3.android.ufcm"
android:layout_height="fill_parent" android:layout_width="wrap_content">
<TabHost android:id="@+id/tabhost" android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout android:layout_width="fill_parent"
android:id="@+id/home_layout" android:orientation="vertical"
android:layout_height="fill_parent">
<TabWidget android:id="@android:id/tabs"
android:layout_width="fill_parent" android:layout_height="wrap_content" />
<FrameLayout android:id="@android:id/tabcontent"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<RelativeLayout android:id="@+id/emptylayout1"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<!--
programatically added tabs will appear here, usually one per
activity
-->
</FrameLayout>
</LinearLayout>
</TabHost>
<LinearLayout android:layout_width="fill_parent"
android:id="@+id/ad_layout" android:layout_height="wrap_content"
android:gravity="bottom" android:layout_alignParentBottom="true"
android:layout_alignBottom="@+id/home_layout">
<com.admob.android.ads.AdView android:id="@+id/ad"
android:layout_width="fill_parent" android:layout_height="wrap_content"
myapp:backgroundColor="#000000" myapp:primaryTextColor="#FFFFFF"
myapp:secondaryTextColor="#CCCCCC"
myapp:keywords="words" />
</LinearLayout>
</RelativeLayout>
Thật không may, trong đó, MapView của tôi trong tab đầu tiên đặt điều khiển Thu phóng trên đầu trang của AdView. Có một số bố cục đơn giản tôi đang thiếu? Tôi có thể lấy TabWidget để wrap_content cho chiều cao, hoặc AdView để wrap_content cho chiều cao, nhưng chỉ khi họ đi trên "@android: id/tabcontent."
Mọi thứ bên dưới nội dung tab được MapView ăn.
Cảm ơn