【发布时间】:2016-03-09 17:16:38
【问题描述】:
我创建了一个布局 XML 并以正确的顺序调用 setCustomTabView 并验证它与此处描述的差不多。
How can custom tab view be implemented using setCustomTabView method in SlidingTabColor sample?
我不想要图像。我只想控制文字大小。我希望在小型手机上使用默认设置,但在平板电脑上使用两倍大小。默认值在平板电脑上非常小。该应用程序在户外使用,可见性和大按钮很重要。到目前为止,我有两个“桶”。以下示例为默认示例。
如果我使用这种 xml 布局,我只能看到第一个选项卡的文本,而看不到着色器。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Default sized TextView for tab title.
This allows us to specify a larger one for tablets in layout-w720dp. -->
<TextView
android:id="@+id/tab_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textSize="18dp"/>
</LinearLayout>
如果我为图像添加 xml 并提供源代码,它就可以工作。如果我省略源,结果与只有 TextView 的布局相同。
<TextView
android:id="@+id/tab_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textSize="18dp"/>
<ImageView
android:layout_width="wrap_content"
android:src="@drawable/ic_launcher"
android:layout_height="wrap_content" />
在我的一个实验中,我增加了文本大小(非常大),并且在没有图像的情况下,我得到了所有四个标签标题。
如何仅使用 TextView 复制默认选项卡标题? (我有一个可行的解决方案,我在运行时检测到指标并将文本大小加倍,但我想通过不同的布局子文件夹来控制它。)
我看到默认的 tabView 是一个简单的实例化 TextView 并且 tabTitleView 等同于它。如果我可以在布局中的 TextView 上执行findViewById,我也可以这样做。但是这样做的尝试导致了一个空的 TextView - 可能是因为尚未建立 ViewGroup。但是如果我使用我的布局,孩子已经有一个父母,并且不能在标签条的 addView() 中使用。
【问题讨论】: