2012-07-03 4 views
2

TableView에서 ImageView를 추가하고 싶습니다. 나는 모든 일을하지만 아무것도 보이지 않는다. 어떻게 해결할 수 있습니까? 당신이 TableRow를 추가하는 데 사용되기 때문에ImageView in TableLayout

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.buddy_list); 

    TableLayout buddy_list_layout = (TableLayout)findViewById(R.id.buddy_list_layout); 

    TableRow tableRow = new TableRow(this); 
    TableLayout.LayoutParams layoutParams1 = new TableLayout.LayoutParams(
    TableLayout.LayoutParams.FILL_PARENT, 
     50); 

    ImageView imageView = new ImageView(this); 
    imageView.setImageResource(R.drawable.troll_logo); 
    TableLayout.LayoutParams layoutParams2 = new TableLayout.LayoutParams(50, 50); 
    tableRow.addView(imageView, layoutParams2); 
    buddy_list_layout.addView(tableRow, layoutParams1); 
} // end -> method -> onCreate 
+1

동적이어야합니까? xml을 통해 이것을하는 것이 더 쉽다면 ... – matt5784

+0

예. 나는 역동적이되고 싶다. –

답변

0

행에 미리 정의 된 xml 레이아웃을 사용하십시오 (누군가가 여기에 제안한 것처럼) : https://stackoverflow.com/a/8679835/375929 (완전히 동적 인 것은 아니며 행이 유사 할 가능성이 높으며 동적으로 추가해야 함) 당신은 프로그래밍으로 LayoutParams 물건의 노력.

하지만, 문제는 아마도 잘못된 LayoutParams 클래스를 사용하고있는 것입니다. 왜냐하면 matt5784는 말합니다.

1

당신이하는 TableRow.LayoutParams()TableLayout.LayoutParams()에서 layoutParams2을 전환해야합니다

이 내 코드입니다. 유형이 레이아웃과 일치해야합니다. 그렇지 않으면 작동하지 않습니다.