【发布时间】:2012-11-02 10:11:23
【问题描述】:
我是 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>
我在这里发现了一个类似的问题:create custom tab in 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
谁能告诉我我做错了什么?
【问题讨论】:
-
您在此处分享的上述参考代码中哪里遇到问题了。
-
@chintankhetiya 我不知道在我的代码中在哪里扩展我的布局。我是新手,所以使用片段比较模糊。
-
@chintankhetiya 嘿,我设法在代码中扩展了我的布局,但是当我将栏移到底部时,背景会填满页面。但是当我在图形布局中预览它时,背景不会填满页面。让我粘贴一些图像和我的布局代码
-
顺便说一句,使用其他操作系统的设计模式不是一个好习惯。见:developer.android.com/design/patterns/pure-android.html
-
是的@C.d。我知道这一点,这就是为什么我一直在努力解决它,并且很难为它获得资源,但我的项目需要我这样做。我无法逃避它,因为我必须满足一些要求。但是感谢您的信息:)
标签: android android-layout android-fragments android-tabhost android-fragmentactivity