首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在没有图像的情况下指定自定义选项卡视图?

如何在没有图像的情况下指定自定义选项卡视图?
EN

Stack Overflow用户
提问于 2016-03-09 17:16:38
回答 1查看 50关注 0票数 0

我创建了一个布局XML,并按正确的顺序调用了setCustomTabView,并验证了它与这里描述的大致相同。

How can custom tab view be implemented using setCustomTabView method in SlidingTabColor sample?

我不想要照片。我只想控制文本大小。我想要一部小型手机的默认设置,但平板电脑的尺寸是它的两倍。默认情况下,平板电脑是很小的。该应用程序用于户外,能见度和大按钮是很重要的。到目前为止我有两个“水桶”。下面的示例用于默认情况。

如果我使用这个xml布局,我只看到第一个选项卡的文本,而没有着色器。

代码语言:javascript
运行
复制
<?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的布局相同。

代码语言:javascript
运行
复制
     <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上做一个TextView,我也可以这样做。但是尝试这样做会导致空TextView --可能是因为还没有建立ViewGroup。但是,如果我使用我的布局,子元素已经有一个父级,不能在选项卡条的addView()中使用。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-03-10 15:35:16

这个成功了。

代码语言:javascript
运行
复制
<TextView
    android:id="@+id/tab_title"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textStyle="bold"
    android:textSize="12sp"
    android:gravity="center_vertical|center_horizontal"
    android:padding="16dp" />

使用调试器(并查看创建默认tabView的源代码),我看到TextView的重力为0x800033,而他们的重力为0x000011。改变android:重力,添加与默认相同的填充,修复它。我认为center也能工作。它是垂直横向(1<<4|1<<0)的别名。

为了保持一致性,我还在tabTitleView上调用了tabTitleView

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35898258

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档