【发布时间】:2015-04-28 16:00:59
【问题描述】:
我为我的 Android 应用中的选项卡活动自定义了选项卡布局。问题是如何垂直居中。文本自动水平居中。我试着写gravity:center,layout_gravity:center。更重要的是:我尝试在我的TextView 中写出精确的高度,但没有任何效果(实际上精确的像素效果很好,但是当我改变设备方向时 - 文本不是中心方向的。
这是我的标签布局代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/tab_name"
android:paddingTop="11dp"
android:paddingBottom="11dp"
android:layout_width="match_parent"
android:textSize="14dp"
android:textStyle="bold"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:maxLines="1"
android:layout_gravity="center" />
</LinearLayout>
这是我的问题的屏幕截图:
【问题讨论】:
-
我不太确定出了什么问题。你能发布一些可以帮助的图像。另外 dp 中 textview 的高度和宽度是多少?
-
你想让文本或小部件垂直居中什么?
-
@ngoa 我用我的问题的图片链接更新了帖子
-
@StepanMazokha 您是否尝试使用 actionBar 并看到它有效?只是一个建议!
-
@ngoa 你说“使用actionBar”是什么意思?顺便说一句,我以这种方式以编程方式添加选项卡: mCustomView = (LinearLayout) getLayoutInflater().inflate(R.layout.custom_tab, null); textView = (TextView)mCustomView.findViewById(R.id.tab_name); textView.setText(mSectionsPagerAdapter.getPageTitle(i)); actionBar.addTab(actionBar.newTab().setCustomView(mCustomView).setTabListener(mActivity));
标签: android tabs android-viewpager android-tabhost