Android 动态添加时,不会显示TextView
我正在动态添加一个文本视图,它没有出现,似乎有什么问题 以下两行之间是否存在差异:Android 动态添加时,不会显示TextView,android,android-layout,Android,Android Layout,我正在动态添加一个文本视图,它没有出现,似乎有什么问题 以下两行之间是否存在差异: receiptLayout.addView(order_1_confirm); ((LinearLayout) receiptLayout).addView(order_1_confirm); 好吧,两个都不行 My activity_receive.xml: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/androi
receiptLayout.addView(order_1_confirm);
((LinearLayout) receiptLayout).addView(order_1_confirm);
好吧,两个都不行
My activity_receive.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/receiptMainLinearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<ImageView
android:id="@+id/image_view_rsc_logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/rsc_logo"
android:src="@drawable/rsc" />
}只需在您的
线性布局中给出android:orientation=“vertical”
而且
LinearLayout receiptLayout = (`LinearLayout`)findViewById(R.id.receiptMainLinearLayout);
您已经将视图强制转换为线性布局,因此无需再次强制转换它设置文本视图的大小和颜色
。可能它看起来不可见,因为它与背景颜色相同。您应该始终向线性布局添加方向,添加android:orientation=“vertical”
就可以了
LinearLayout receiptLayout = (`LinearLayout`)findViewById(R.id.receiptMainLinearLayout);