您好我不明白为什么会收到此错误:10-08 10:23:40.433:E / MoreInfoHPW_ViewGroup(10127):父视图不是TextView 任何帮助将不胜感激。
LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.custom_toast_screen_pass,
(ViewGroup) findViewById(R.id.layout_pass));
Toast toast = new Toast(getApplicationContext());
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.setDuration(Toast.LENGTH_SHORT);
toast.setView(layout);
toast.show();
和XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_pass"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:padding="10dp"
android:background="@drawable/background_9" >
<ImageView
android:id="@+id/approval_icn"
android:layout_height="40dp"
android:layout_width="40dp"
android:src="@drawable/approval_icon"
android:layout_gravity="center_vertical" >
</ImageView>
<TextView
android:id="@+id/pass_txt"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"
android:textColor="#FFFFFF"
android:textSize="20sp"
android:text="Congratulations you have passed the quiz" >
</TextView>
</LinearLayout>
答案 0 :(得分:0)
LayoutInflater的第二个参数看起来很奇怪。
(ViewGroup) findViewById(R.id.layout_pass)
是对布局中要膨胀的id的引用,但该参数用于将根布局传递给膨胀对象。尝试将null
作为第二个参数传递。