【发布时间】: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