没有viewpager的自定义Tablayout隐藏了textview

Custom Tablayout without viewpager having textview hidden

所以,我有一个带有文本和下方圆形黑点的自定义标签布局,以向用户表明他们需要单击它。所以,我的 tablayout 没有任何 viewpager。我尝试了 notification badger,但它在 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>

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

您的 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>