2012-02-19 1 views
1

코드를 Android TextView에 어떻게 적용 할 수 있습니까?Android - 코드에 9 개의 패치 적용

왜 물어볼 수 있습니까? 왜냐하면 나는 컨트롤의 수를 동적으로 설정해야하기 때문이다. 난

는 비슷한과 그 작동하지 수행하려고 :

(코드 내 9 패치 "notif_bubble_white.9.png는"R.drawable.notif_bubble_white입니다)

tv = new TextView(this); 
    tv.setText("Test Message"); 
    tv.setLayoutParams(lpL); 
    tv.setPadding(0, 0, paddingValue, 0); 
    CustomFonts.ApplyFont_Custom1(tv, context); 
    tv.setBackgroundResource(R.drawable.notif_bubble_white); 
    // tv.setTextColor(TxtColFromCl); 
    layout.addView(tv); 

경우 LPL

LinearLayout.LayoutParams lpL = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, 
     LinearLayout.LayoutParams.WRAP_CONTENT); 
+1

질문은 어디에 있습니까? – noob

+0

"Android TextView에 9 패치를 적용하려면 어떻게해야합니까?" 그의 질문이 있습니다. –

답변

0

당신이 중 하나를 그냥 컨트롤의 수를 알 수없는 경우, c는 모두 한 번에 컨트롤을 만들고 필요할 때까지 control.setVisibility(View.GONE) 그들을 숨기거나 할 수 있습니다로 정의 하였다 this question에 설명 된 것처럼 레이아웃 파일을 부 풀리십시오.

button.xml :

<Button 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/button01" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" /> 

버튼 팽창 :

button = (Button) getLayoutInflater().inflate(R.layout.button, null); 
를 참조 질문에서 복사

코드 (세드릭, 또는 Pentium10 학점, 나도 몰라, 그리고 가정 컨트롤은 버튼입니다)

+0

XML 코드에서 9patch 배경을 추가하면 인플레이터는 항상 9patch를 올바르게 팽창시킵니다. –