1

私は Android が初めてで、オンラインで見つけたコードから FragmentActivity を使用してタブを作成しようとしました。 http://thepseudocoder.wordpress.com/2011/10/04/android-tabs-the-fragment-way/

これは私の 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>

ここで同様の質問を見つけました: FragmentActivity でカスタム タブを作成しますが、コードにソリューションを適用する方法がわかりませんでした。誰か教えてくれませんか?ありがとうございました。

アップデート:

コードでカスタム レイアウトを拡張することができました。しかし、私は別のエラーに直面しました。これは私の最新のコードhttp://pastie.org/pastes/5187362/text?key=74r87diquysvruwsam1tqを AdilSoomro http://adilsoomro.blogspot.com/2011/06/iphone-like-tabs-in-から FragmentActivity に微調整したものですandroid.htmlコード (TabActivity を使用) からの参照を含む

私の最新のコードは、そのレイアウト(tab_indicator.xml)にhttp://pastie.org/pastes/5187408/text?key=qxxa5xxrhsburebllyhmwを設定して、このようにレイアウトを正常に膨らませます

ここに画像の説明を入力 しかし、タブを下に揃える必要があります。下に揃えると、コード layout_gravity="bottom" はグラフィカル レイアウトで機能しましたが、実行すると、相対レイアウトの背景が画面全体を埋め尽くします。コードhttp://pastie.org/pastes/5187445 /text?key=6dz2tsiggey9se51d2thtq

ここに画像の説明を入力

誰かが私が間違ったことを教えてもらえますか?

4

2 に答える 2

1

解決しました!ついに!私が参照した他のリソースをテストした後、RelativeLayoutのlayout_alignParentBottomは結果をもたらさないことに気付きました。したがって、代わりにTabWidgetを下に揃えてみましたが、うまくいきました。

これは、TabHostとTabWidgetを含む私のmain.xmlです。 http://pastie.org/pastes/5188297/text?key=lqfp3jnofs5kgsvslm3yg

tab_indicator.xml /テキストと画像の設定を次のように保持します:http ://pastie.org/pastes/5187408/text?key = qxxa5xxrhsburebllyhmw

そして、これがFragmentActivityを使用するカスタムiPhoneタブです:

P / S:申し訳ありませんが、私のJavaファイルが混乱している場合、私は新しいです。何か間違ったことがある場合は、教えてください。

ここに画像の説明を入力してください

于 2012-11-05T09:37:45.937 に答える
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>
于 2012-11-05T05:23:12.660 に答える