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调整为 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)

在此处输入图像描述 但我需要将标签对齐到底部。当我将它对齐到底部时,代码 layout_gravity="bottom" 在图形布局上工作,但是当我运行它时,我的相对布局的背景会填满整个屏幕,就像代码http://pastie.org/pastes/5187445 /text?key=6dz2tsiggey9se51d2thtq

在此处输入图像描述

有人可以告诉我我做错了什么吗?

4

2 回答 2

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 文件令人困惑,我是新手,如果我做错了什么,请告诉我。

在此处输入图像描述

于 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 回答