5

http://bakhtiyor.com/2009/10/iphonish-tabs/に投稿された例を調べていましたが、実際には、Tabviewの代わりにラジオボタンを配置しています。

しかし、問題は、画像を中央に設定できないことです。その常に左に揃えられます。

これがスクリーンショットです。ビューをこのようにしたいのですが、代わりに画像を中央に配置したいと思います。 ここに画像の説明を入力してください

これが私のレイアウトXMLファイルの外観です

    <?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@android:id/tabhost" 
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">

  <LinearLayout android:orientation="vertical"
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent">

    <FrameLayout android:id="@android:id/tabcontent"
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content"
      android:layout_weight="1" 
      android:padding="20dip"/>

    <RadioGroup android:layout_width="fill_parent"
      android:layout_height="wrap_content" 
      android:orientation="horizontal"
      android:checkedButton="@+id/allcontacts"
      android:gravity="center"
      android:id="@+id/contactgroup">


      <RadioButton android:id="@+id/allcontacts" 
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:layout_weight="1"
      android:orientation="vertical"
      android:background="@drawable/button_radio"/>


      <RadioButton
          android:id="@+id/categories"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:layout_weight="1"
          android:background="@drawable/button_radio"
          android:orientation="vertical"
          android:layout_gravity="center|right"/>

      <RadioButton android:id="@+id/favourites" 
   android:layout_width="fill_parent"
          android:layout_height="wrap_content"

    android:gravity="center"
    android:orientation="vertical"
      android:layout_weight="1" 
      android:background="@drawable/button_radio"/>

    </RadioGroup>

    <TabWidget android:id="@android:id/tabs"
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content"
      android:layout_weight="0" android:visibility="gone" />
  </LinearLayout>
</TabHost>

アドバイスしてください

デフォルトのタブウィジェットを使用した後の更新された画像 ここに画像の説明を入力してください

デフォルトのタブビューで上記のラジオボタンのようにカスタマイズすることは可能ですか?

4

2 に答える 2

3

実際には画像を中央に配置しませんが、そのように表示することはできます...画像を変更して、左側に空白を入れ、画像のすぐ右側を切り取ることができます。

編集

これらのいずれかを見たことがあるかどうかはわかりませんが、興味を持ったので、探しに行って、下部のタブの最終的な目標に役立つ可能性のあるいくつかのリンクを見つけました。

ニコのブログ

SO質問回答

別のSO質問回答

幸運を!

編集2

わかりました、それを見つけました。RadioButtonから新しいクラスを拡張し、onDraw()をオーバーライドしてから、コードがプラットフォーム定義の属性を取得できるように、res/valuesに配置する必要のあるattrs.xmlファイルを作成する必要があります。

ここに特定のコード

于 2012-05-06T06:00:32.970 に答える
0

を拡張する独自のImageButtonを定義できますCompoundButton。それを行う方法については、RadioButtonとのソースを参照してください。CompoundButton

于 2012-05-06T05:02:49.353 に答える