2017-12-31 4 views
2

setPadding이 내 코드에서 작동하지 않습니다. 모든 카드가 함께 연결되어있는 것으로 보입니다. 패딩이 적용되지 않았 음을 나타냅니다.동적으로 CardView를 만들 때 setPadding()이 작동하지 않습니다.

card = new CardView(mContext); 

      // Set the CardView layoutParams 
LayoutParams params = new LayoutParams(
    LayoutParams.MATCH_PARENT, 
    LayoutParams.WRAP_CONTENT 
    ); 
card.setLayoutParams(params); 

      //Set CardView Padding 
card.setPadding(15,15,15,15); 

      // Set CardView corner radius 
card.setRadius(8); 

      // Set cardView content padding 
card.setContentPadding(15, 15, 15, 15); 

답변

1

세트 cardView 내용 패딩을 사용할 수 있습니다.

CardView card = new CardView(mContext); 

       // Set the CardView layoutParams 
       LayoutParams params = new LayoutParams(
         LayoutParams.WRAP_CONTENT, 
         LayoutParams.WRAP_CONTENT 
       ); 
       card.setLayoutParams(params); 

       // Set CardView corner radius 
       card.setRadius(10); 

       // Set cardView content padding 
       card.setContentPadding(15, 15, 15, 15); 


       // Set the CardView maximum elevation 
       card.setMaxCardElevation(15); 

       // Set CardView elevation 
       card.setCardElevation(10); 

편집

LayoutParams params = new LayoutParams(
    LayoutParams.WRAP_CONTENT, 
    LayoutParams.WRAP_CONTENT 
); 
params.setMargins(10, 10, 10,10); 
+0

.... 나는 카드와의 사이에 두 개의 서로 다른 카드가없는 사이에 패딩이 필요합니다 내용 – ShrG

+0

여백이 필요합니다. ** params.setMargins (10, 10, 10,10); ** –

+0

내 편집 ans를 확인하십시오. –

1

사용 card.setContentPadding(10, 10, 10, 10); 대신 이미 setContentPadding을 사용했습니다 card.setPadding(15,15,15,15);

관련 문제