【问题标题】:Custom Tablayout without viewpager having textview hidden没有 viewpager 的自定义 Tablayout 隐藏了 textview
【发布时间】:2020-01-25 07:37:00
【问题描述】:

所以,我有一个带有文本的自定义选项卡布局,其下方有一个圆形黑点,以向用户显示他们需要单击它。所以,我的 tablayout 没有任何 viewpager。我尝试了通知獾,但它在 tablayout 中不起作用。

MainClass.java

public class MainActivity extends AppCompatActivity {

        TabLayout tabLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        tabLayout = findViewById(R.id.tablayout);

        View view = (FrameLayout)LayoutInflater.from(this).inflate(R.layout.custom_layout, null);
        TextView tv = (TextView) view.findViewById(R.id.textview);
        tv.setText("This is cool");


        tabLayout.addTab(tabLayout.newTab().setCustomView(view));



    }
}

cusotm_layout.xml

<?xml version="1.0" encoding="utf-8"?>

<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
     android:layout_height="match_parent">

    <TextView
        android:layout_width="wrap_content"
        android:id="@+id/textview"
        android:text="SOmetext "

        android:layout_height="wrap_content"
        android:textColor="@color/colorPrimaryDark"
        android:layout_gravity="center" />

    <ImageView
        android:layout_width="100dp"
        android:src="@drawable/bg_card_elements"
        android:id="@+id/imageview"
        android:layout_gravity="bottom|center"
        android:layout_height="100dp">

    </ImageView>

</FrameLayout>

我不知道为什么我的文字不可见。任何想法?

【问题讨论】:

  • 我通过将我的视图转换为 (FrameLayout) 来解决它,但我根本看不到文本。我该怎么做?

标签: android xml android-layout layout android-tablayout


【解决方案1】:

您的 textview 隐藏在 imageview 后面,因此不显示。

像这样切换imageview和textview

cusotm_layout.xml

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

<ImageView
        android:layout_width="100dp"
        android:src="@drawable/bg_card_elements"
        android:id="@+id/imageview"
        android:layout_gravity="bottom|center"
        android:layout_height="100dp">

</ImageView>

<TextView
        android:layout_width="wrap_content"
        android:id="@+id/textview"
        android:text="SOmetext "
        android:layout_height="wrap_content"
        android:textColor="@color/colorPrimaryDark"
        android:layout_gravity="center" /></FrameLayout>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-07
    • 2018-04-25
    • 2017-03-10
    相关资源
    最近更新 更多