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问题答案

祝你好运!

编辑 2

好的,找到了。您必须从 RadioButton 扩展一个新类并覆盖 onDraw(),然后创建一个 attrs.xml 文件,您需要将其放入 res/values 以便代码可以获取平台定义的属性。

具体代码在这里

于 2012-05-06T06:00:32.970 回答
0

您可以定义自己的 ImageButton 扩展CompoundButton。请参阅RadioButtonandCompoundButton的源代码以了解如何操作。

于 2012-05-06T05:02:49.353 回答