gpt4 book ai didi

android - 如何在 FragmentActivity 中使用自定义 iPhone 选项卡?

转载 作者:行者123 更新时间:2023-11-30 03:57:01 24 4
gpt4 key购买 nike

我是 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://pastie.org/pastes/5187408/text?key=qxxa5xxrhsburebllyhmw其布局 (tab_indicator.xml)

enter image description here但我需要将标签对齐到底部。当我将它对齐到底部时,代码 layout_gravity="bottom"在图形布局上起作用,但是当我运行它时,我的相关布局的背景填满了整个屏幕,就像代码 http://pastie.org/pastes/5187445/text?key=6dz2tsiggey9se51d2thtq 一样

enter image description here

谁能告诉我我做错了什么?

最佳答案

解决了!最后!在测试了我提到的其他资源之后,我意识到 RelativeLayout 中的 layout_alignParentBottom 没有给出任何结果。因此,我尝试将 TabWidget 对齐到底部,并且成功了!

这是我的包含 TabHost 和 TabWidget 的 main.xml。 http://pastie.org/pastes/5188297/text?key=lqfp3jnofs5kgsvslm3yg

像这样保留 tab_indicator.xml/文本和图像的设置:http://pastie.org/pastes/5187408/text?key=qxxa5xxrhsburebllyhmw

这是一个使用 FragmentActivity 的自定义 iPhone 选项卡:

P/S :抱歉,如果我的 Java 文件令人困惑,我是新手,如果我做错了什么,请告诉我。

enter image description here

关于android - 如何在 FragmentActivity 中使用自定义 iPhone 选项卡?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13193189/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com