我创建了包含问题文本和适合问题的输入字段的表单。我的表单中有spinner,edittext和checkbox。 所有都是使用活动动态创建的。创建的布局中的问题是输入字段正确显示但文本视图未显示。
private void showIssueForm(){
for (int i=0;i<claimQuestionList.size();i++){
ClaimQuestion claimQuestion=claimQuestionList.get(i);
LinearLayout linearLayout=ClaimUtils.createLayoutForClaimQuestion(claimQuestion,this);
/*claimQuestionsLinearLayout.addView(linearLayout);*/
claimQuestionsLinearLayout.addView(linearLayout,i);
}
}
private static TextView createTextView(ClaimQuestion claimQuestion,Context context){
TextView textView=new TextView(context);
LinearLayout.LayoutParams textViewLayoutParams=new LinearLayout.LayoutParams(300,80,1);
textView.setText("hi m printing the text what are you looking for");//claimQuestion.getOrder()+". "+claimQuestion.getLabel());
textView.setLayoutParams(textViewLayoutParams);
//textView.setMinLines(1);
// textView.setSingleLine(false);
textView.setTextSize(R.dimen.system12);
textView.setVisibility(View.VISIBLE);
textView.setTextColor(context.getResources().getColor(R.color.light_white_));
return textView;
}
我添加表单元素的线性布局如下所示
public static LinearLayout createLayoutForClaimQuestion(ClaimQuestion claimQuestion,Context context){
LinearLayout linearLayout=new LinearLayout(context);
LinearLayout.LayoutParams linearLayoutParams=new LinearLayout.LayoutParams(500,200);
linearLayout.setLayoutParams(linearLayoutParams);
linearLayout.setOrientation(LinearLayout.VERTICAL);
TextView questionLabel=createTextView(claimQuestion,context);
linearLayout.addView(questionLabel,0);
if (claimQuestion.getQuestionType()==ClaimQuestion.QuestionTypeEnum.CQ_TEXT){
EditText editText=createEditText(claimQuestion,context);
linearLayout.addView(editText,1);
}else if(claimQuestion.getQuestionType()==ClaimQuestion.QuestionTypeEnum.CQ_CHECKBOX){
CheckBox checkBox=createCheckBox(claimQuestion,context);
linearLayout.addView(checkBox,1);
}else if(claimQuestion.getQuestionType()==ClaimQuestion.QuestionTypeEnum.CQ_SELECT){
Spinner spinner=createSpinner(claimQuestion,context);
linearLayout.addView(spinner,1);
}
return linearLayout;
}
父布局的xml布局文件是
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.maximus.mycar.VehicleSelectActivity"
android:background="@drawable/bluebg_320_568">
<include layout="@layout/header"
android:id="@+id/top_header_layout_ici"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_marginTop="10dp"/>
<ScrollView
android:id="@+id/claim_questions_scroll_view"
android:layout_below="@id/top_header_layout_ici"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:layout_marginBottom="20dp"
>
<LinearLayout
android:id="@+id/claim_questions_linear_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
</LinearLayout>
</ScrollView>
答案 0 :(得分:1)
我通过设置固定值来更改字体大小,然后它工作正常。
textView.setTextSize(12);
答案 1 :(得分:0)
使用这个: -
textView.setTextColor(getResources().getColor(R.color.light_white_));
而不是: -
textView.setTextColor(context.getResources().getColor(R.color.light_white_));
如果有效,请告诉我。)