我是 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://android.codeandmagic.org/2011/07/android-tabs-with-fragments/
- http://thepseudocoder.wordpress.com/2011/10/04/android-tabs-the-fragment-way/
我的最新代码成功地像这样膨胀了布局,其布局设置为http://pastie.org/pastes/5187408/text?key=qxxa5xxrhsburebllyhmw (tab_indicator.xml)
但我需要将标签对齐到底部。当我将它对齐到底部时,代码 layout_gravity="bottom" 在图形布局上工作,但是当我运行它时,我的相对布局的背景会填满整个屏幕,就像代码http://pastie.org/pastes/5187445 /text?key=6dz2tsiggey9se51d2thtq
有人可以告诉我我做错了什么吗?