1

我是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://pastie.org/pastes/5187408/text?key=qxxa5xxrhsburebllyhmw(tab_indicator.xml)

enter image description here 但我需要將我的標籤對齊到底部。當我將其調整至底部,代碼layout_gravity =「底」圖形化佈局的工作,但是當我運行它,我相對佈局的背景充滿整個屏幕,這樣的代碼http://pastie.org/pastes/5187445/text?key=6dz2tsiggey9se51d2thtq

enter image description here

能有人告訴我我做錯了什麼?

+0

你在哪裏得到了上述參考代碼中的問題,你在這裏分享。 –

+0

@chintankhetiya我不知道在哪裏膨脹我的代碼佈局。我是新來的,所以使用片段模糊。 –

+0

@chintankhetiya嘿我設法膨脹我的代碼佈局,但是,當我將欄移動到底部,背景填充頁面。但是當我在圖形佈局中預覽它時,背景不會填充頁面。讓我粘貼一些圖像和我的佈局代碼 –

回答

1

解決它!最後!在測試了我提到的其他資源之後,我意識到RelativeLayout中的layout_alignParentBottom不會給出任何結果。因此我嘗試將TabWidget對齊到底部,並且它工作正常!

這是我的main.xml,它包含TabHost和TabWidget。 http://pastie.org/pastes/5188297/text?key=lqfp3jnofs5kgsvslm3yg

保持tab_indicator.xml /文本和圖像這樣的設置:http://pastie.org/pastes/5187408/text?key=qxxa5xxrhsburebllyhmw

這裏是使用FragmentActivity的定製iPhone標籤:

P/S:很抱歉,如果我的Java文件很混亂,我是新手,如果有什麼我做錯了,請告訴我。

enter image description here

0

嘗試這個蜂蜜>

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="55dp"  
    android:layout_weight="1" 
    android:orientation="vertical" 
    android:layout_gravity="bottom" 
    android:background="@android:drawable/title_bar" 
    android:padding="5dp"> 

    <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"/> 

    <ImageView 
     android:id="@+id/icon" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_centerVertical="true" 
     android:src="@drawable/ic_action_search" /> 

     <ImageView 
      android:id="@+id/icon" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:layout_centerVertical="true" 
      android:layout_marginLeft="49dp" 
      android:src="@drawable/ic_action_search" /> 

</RelativeLayout> 
+0

我試過你的代碼,但我得到了相同的結果。 –

+0

在不同的文件中測試我的代碼。它應該在下面對齊。我的猜測是,我的java代碼可能存在問題 –

相關問題