我是Android新手,我嘗試使用我在網上找到的代碼創建一個使用FragmentActivity的選項卡。 http://thepseudocoder.wordpress.com/2011/10/04/android-tabs-the-fragment-way/如何在FragmentActivity中使用自定義iPhone標籤?
這是我FragmentActivity http://pastie.org/pastes/5170802/text?key=jhowuevxe2fshlwu5tisg
我想用使用圖像和文本自定義佈局。
//tab_indicator.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="0dip"
android:layout_height="55dip"
android:layout_weight="1"
android:orientation="vertical"
android:background="@drawable/tab_indicator"
android:padding="5dp">
<ImageView android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:src="@drawable/icon"/>
<TextView android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
style="?android:attr/tabWidgetStyle"/>
</RelativeLayout>
我發現了一個類似的問題在這裏:create custom tab in FragmentActivity但我無法弄清楚如何在我的代碼應用的解決方案。有人能教我如何?謝謝。
更新:
我設法在代碼中誇大自定義佈局。但我面臨另一個錯誤。這是我最新的代碼http://pastie.org/pastes/5187362/text?key=74r87diquysvruwsam1tq扭捏FragmentActivity,從AdilSoomro http://adilsoomro.blogspot.com/2011/06/iphone-like-tabs-in-android.html碼(使用TabActivity)與一些參考從
- http://android.codeandmagic.org/2011/07/android-tabs-with-fragments/
- http://thepseudocoder.wordpress.com/2011/10/04/android-tabs-the-fragment-way/
我最新的代碼成功地膨脹這樣的佈局,其佈局設置爲http://pastie.org/pastes/5187408/text?key=qxxa5xxrhsburebllyhmw(tab_indicator.xml)
但我需要將我的標籤對齊到底部。當我將其調整至底部,代碼layout_gravity =「底」圖形化佈局的工作,但是當我運行它,我相對佈局的背景充滿整個屏幕,這樣的代碼http://pastie.org/pastes/5187445/text?key=6dz2tsiggey9se51d2thtq
能有人告訴我我做錯了什麼?
你在哪裏得到了上述參考代碼中的問題,你在這裏分享。 –
@chintankhetiya我不知道在哪裏膨脹我的代碼佈局。我是新來的,所以使用片段模糊。 –
@chintankhetiya嘿我設法膨脹我的代碼佈局,但是,當我將欄移動到底部,背景填充頁面。但是當我在圖形佈局中預覽它時,背景不會填充頁面。讓我粘貼一些圖像和我的佈局代碼 –