TextView 在相对布局中不起作用
TextView is not working in relative layout
我在 Relative layout
中遇到问题。我在我的 XML 布局中设置了几个 textviews
,但在 运行 程序之后,it will not show the text on emulator/phone
。之前在想,这是androidstudio更新版本的问题。但我还检查了另一台具有较旧 android 版本的计算机系统。我正在与大家分享 XML 代码。请帮我。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/transition_profile"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@android:color/white">
<ImageView
android:id="@+id/imgv_back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/round_arrow_back_ios_24_px"
android:layout_marginTop="54dp"
android:layout_marginLeft="28dp"
android:layout_alignParentLeft="true"/>
<ImageView
android:id="@+id/imgv_help"
android:layout_width="34dp"
android:layout_height="34dp"
android:src="@drawable/round_help_outline_24_px"
android:layout_alignParentRight="true"
android:layout_marginTop="54dp"
android:layout_marginRight="28dp"/>
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/imgv_boss"
android:layout_width="126dp"
android:layout_height="126dp"
android:src="@drawable/boss"
android:layout_centerInParent="true"
android:layout_alignParentTop="true"
android:layout_marginTop="71dp"/>
<TextView
android:id="@+id/tv_emp_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="24sp"
android:textColor="#262d3d"
android:letterSpacing="0.02"
tools:text="Ramesh Singha"
android:fontFamily="@font/roboto_slab_bold"
android:layout_below="@id/imgv_boss"
android:layout_centerInParent="true"
android:layout_marginTop="26dp"/>
<TextView
android:id="@+id/tv_boss_profile_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14sp"
android:textColor="#6c7383"
android:letterSpacing="0.02"
android:layout_below="@id/tv_emp_name"
tools:hint="Field Manager"
android:fontFamily="@font/roboto_slab_regular"
android:layout_centerInParent="true"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"/>
<LinearLayout
android:id="@+id/ll_tabslides"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#fff"
android:layout_below="@id/tv_boss_profile_name">
<com.google.android.material.tabs.TabLayout
android:id="@+id/tblyt_profile"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:elevation="6dp"
android:minHeight="?attr/actionBarSize"
app:tabIndicatorColor="#0091ea"
app:tabSelectedTextColor="#0091ea"
app:tabTextColor="#6c7383"
tools:targetApi="lollipop"/>
<androidx.viewpager.widget.ViewPager
android:id="@+id/vpgr_profile"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
</RelativeLayout>
您正在 textView
中使用 tools:text="Ramesh Singha"
,用于测试目的。如果你想设置 text
,你应该使用以下选项
android:text="Ramesh Singha"
在代码中添加
<TextView
android:id="@+id/tv_emp_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="24sp"
android:textColor="#262d3d"
android:letterSpacing="0.02"
tools:text="Ramesh Singha"
android:fontFamily="@font/roboto_slab_bold"
android:layout_below="@id/imgv_boss"
android:layout_centerInParent="true"
android:layout_marginTop="26dp" />
TextView userName=(TextView)findViewById(R.id.tv_emp_name)
userName.setText("Ramesh Singha")
对于静态文本,使用
android:text="Ramesh Singha"
而不是
tools:text="Ramesh Singha"
对于动态文本,使用
.xml File
<TextView
android:id="@+id/tv_boss_profile_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14sp"
android:textColor="#6c7383"
android:letterSpacing="0.02"
android:layout_below="@id/tv_emp_name"
tools:hint="Field Manager"
android:fontFamily="@font/roboto_slab_regular"
android:layout_centerInParent="true"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"/>
.Java File
TextView employeeName=(TextView)findViewById(R.id.tv_emp_name);
employeeName.setText("Ramesh Singha");
我在 Relative layout
中遇到问题。我在我的 XML 布局中设置了几个 textviews
,但在 运行 程序之后,it will not show the text on emulator/phone
。之前在想,这是androidstudio更新版本的问题。但我还检查了另一台具有较旧 android 版本的计算机系统。我正在与大家分享 XML 代码。请帮我。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/transition_profile"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@android:color/white">
<ImageView
android:id="@+id/imgv_back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/round_arrow_back_ios_24_px"
android:layout_marginTop="54dp"
android:layout_marginLeft="28dp"
android:layout_alignParentLeft="true"/>
<ImageView
android:id="@+id/imgv_help"
android:layout_width="34dp"
android:layout_height="34dp"
android:src="@drawable/round_help_outline_24_px"
android:layout_alignParentRight="true"
android:layout_marginTop="54dp"
android:layout_marginRight="28dp"/>
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/imgv_boss"
android:layout_width="126dp"
android:layout_height="126dp"
android:src="@drawable/boss"
android:layout_centerInParent="true"
android:layout_alignParentTop="true"
android:layout_marginTop="71dp"/>
<TextView
android:id="@+id/tv_emp_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="24sp"
android:textColor="#262d3d"
android:letterSpacing="0.02"
tools:text="Ramesh Singha"
android:fontFamily="@font/roboto_slab_bold"
android:layout_below="@id/imgv_boss"
android:layout_centerInParent="true"
android:layout_marginTop="26dp"/>
<TextView
android:id="@+id/tv_boss_profile_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14sp"
android:textColor="#6c7383"
android:letterSpacing="0.02"
android:layout_below="@id/tv_emp_name"
tools:hint="Field Manager"
android:fontFamily="@font/roboto_slab_regular"
android:layout_centerInParent="true"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"/>
<LinearLayout
android:id="@+id/ll_tabslides"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#fff"
android:layout_below="@id/tv_boss_profile_name">
<com.google.android.material.tabs.TabLayout
android:id="@+id/tblyt_profile"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:elevation="6dp"
android:minHeight="?attr/actionBarSize"
app:tabIndicatorColor="#0091ea"
app:tabSelectedTextColor="#0091ea"
app:tabTextColor="#6c7383"
tools:targetApi="lollipop"/>
<androidx.viewpager.widget.ViewPager
android:id="@+id/vpgr_profile"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
</RelativeLayout>
您正在 textView
中使用 tools:text="Ramesh Singha"
,用于测试目的。如果你想设置 text
android:text="Ramesh Singha"
在代码中添加
<TextView
android:id="@+id/tv_emp_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="24sp"
android:textColor="#262d3d"
android:letterSpacing="0.02"
tools:text="Ramesh Singha"
android:fontFamily="@font/roboto_slab_bold"
android:layout_below="@id/imgv_boss"
android:layout_centerInParent="true"
android:layout_marginTop="26dp" />
TextView userName=(TextView)findViewById(R.id.tv_emp_name)
userName.setText("Ramesh Singha")
对于静态文本,使用
android:text="Ramesh Singha"
而不是
tools:text="Ramesh Singha"
对于动态文本,使用
.xml File
<TextView
android:id="@+id/tv_boss_profile_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14sp"
android:textColor="#6c7383"
android:letterSpacing="0.02"
android:layout_below="@id/tv_emp_name"
tools:hint="Field Manager"
android:fontFamily="@font/roboto_slab_regular"
android:layout_centerInParent="true"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"/>
.Java File
TextView employeeName=(TextView)findViewById(R.id.tv_emp_name);
employeeName.setText("Ramesh Singha");