gpt4 book ai didi

Android Design Tablayout 自定义 View 无法匹配父级

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:06:32 25 4
gpt4 key购买 nike

自定义始终在 Tablayout 中居中。表格布局如下。如何让它的父级可用的全部空间,即 TabView。

<android.support.design.widget.TabLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/tablayout"
android:layout_width="match_parent"
app:tabPaddingStart="0dp"
app:tabPaddingEnd="0dp"
android:layout_height="90dp">
</android.support.design.widget.TabLayout>

添加如下 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"
android:background="@android:color/holo_purple"
android:gravity="center_horizontal">

<TextView
android:text="Hello !"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>

但不幸的是,它总是居中并且永远无法获得完整的空间。问题是我无法在选项卡之间提供分隔线,因为它始终位于中间。

添加标签的Java代码:

    TabLayout v = (TabLayout)findViewById(R.id.tablayout);
TabLayout.Tab tab = v.newTab();
tab.setCustomView(R.layout.content_main);
v.addTab(tab);
tab = v.newTab();
tab.setCustomView(R.layout.content_main);
v.addTab(tab);
tab = v.newTab();
tab.setCustomView(R.layout.content_main);
v.addTab(tab)

我分享了图片@ http://i60.tinypic.com/11cdvyf.jpg

最佳答案

错误已在此处注册: https://code.google.com/p/android/issues/detail?id=190429

尽管您可以通过扩充自定义 View 然后手动应用布局参数来解决此问题:

View v = LayoutInflater.from(this).inflate(R.layout.view_goal_tab_active, null);
TextView tv = (TextView)v.findViewById(R.id.goal_tab_active_tv);
tv.setSelected(true);
v.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
mTabs.getTabAt(0).setCustomView(v);

关于Android Design Tablayout 自定义 View 无法匹配父级,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33182988/

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