2016-12-26 1 views
1

프로그래밍 방식으로 수평 구분선을 추가하는 방법, 코드에 표시된대로 각 추가 된 뷰를 linearlayout에 추가 할 후 가로 분할자를 추가하려고합니다. 내가 가진 문제는 런타임에 디바이더가 표시되지 않는다는 것입니다.bleow 게시 코드에서

왜 디바이더가 표시되지 않고 어떻게 나타나는지 알려주십시오.

코드 :

private void inflateView(String bez, String ges) { 
    LinearLayout linLay = (LinearLayout) findViewById(R.id.versicherungsListeActivity2mod_linLay_meineDocList_container); 

    //divider 
    View viewDivider = new View(this); 
    viewDivider.setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); 
    viewDivider.setBackgroundColor(Color.parseColor("#000000")); 

    LayoutInflater inflator = this.getLayoutInflater(); 
    View view = inflator.inflate(R.layout.versicherung_docs_row_model, null);//<<<<<< this is the view i want to add to the map as a key 

    ImageView imgViewLogo = (ImageView) view.findViewById(R.id.versicherungslisteactivity2_docs_lisvie_row_model_imgVie_logo); 
    TextView texVieBez = (TextView) view.findViewById(R.id.versicherungslisteactivity2_docs_lisvie_row_model_texVie_docBezeichnung); 
    TextView texVieExtraItem = (TextView) view.findViewById(R.id.versicherungslisteactivity2_docs_lisvie_row_model_texVie_addMoreDocs); 
    TextView texVieGes = (TextView) view.findViewById(R.id.versicherungslisteactivity2_docs_lisvie_row_model_texVie_docGesellschaft); 
    Button btnMore = (Button) view.findViewById(R.id.versicherungslisteactivity2_docs_lisvie_row_model_btn_more); 


    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 
     imgViewLogo.setImageDrawable(this.getResources().getDrawable(R.drawable.insurance_details_doc, this.getTheme())); 
    } else { 
     imgViewLogo.setImageDrawable(this.getResources().getDrawable(R.drawable.insurance_details_doc)); 
    } 

    texVieBez.setText(bez); 
    texVieGes.setText(bez); 
    btnMore.setVisibility(View.VISIBLE); 

    linLay.addView(view); 

    linLay.addView(viewDivider); 
} 

답변

2

viewDivider 높이 WRAP_CONTENT를 가지며보기 비어로서, 그 높이가 넌 디바이더의 원하는 높이를 설정할 필요가 0

계산된다.

int dividerHeight = getResources().getDisplayMetrics().density * 1; // 1dp to pixels 
viewDivider.setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, dividerHeight));