簡體   English   中英

textview沒有顯示文字

[英]textview is not showing text

我創建了包含問題文本和適合問題的輸入字段的表單。 我的表單中有微調框,edittext和復選框。 所有這些都是使用activity動態創建的。 創建的布局中的問題是輸入字段顯示正確,但未顯示textview。

   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>

我通過設置固定值來更改字體大小,然后效果很好。

textView.setTextSize(12);

使用這個:

 textView.setTextColor(getResources().getColor(R.color.light_white_)); 

代替這個:

 textView.setTextColor(context.getResources().getColor(R.color.light_white_)); 

請讓我知道它是否有效:)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM