Android TableLayout LayoutInflater HorizontalScrollView inflate Real_G 2011. 9. 8. 17:29 반응형 package net.hybridego.test; import android.app.Activity; import android.content.Context; import android.os.Bundle; import android.view.LayoutInflater; import android.view.ViewGroup; import android.widget.Button; import android.widget.HorizontalScrollView; import android.widget.LinearLayout; import android.widget.TableLayout; import android.widget.TableRow; public class Test_inflate1 extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); LayoutInflater inflate = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); LinearLayout mRoot = (LinearLayout) inflate.inflate(R.layout.channel_select, null); HorizontalScrollView minitable = (HorizontalScrollView) mRoot.findViewById(R.id.ch_table); TableLayout root = new TableLayout(this); TableLayout.LayoutParams parms = new TableLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT, 0.0F); parms.setMargins(1, 1, 0, 0); // 버튼을 배열로 배치,숫자 세팅 for (int i = 0; i < 5; i++) { TableRow tr = new TableRow(this); for (int j = 0; j < 3; j++) { // 버튼생성 Button button = new Button(this); TableRow.LayoutParams buttonParams = new TableRow.LayoutParams(200, ViewGroup.LayoutParams.WRAP_CONTENT); button.setLayoutParams(buttonParams); button.setText("" + i + " " + j); button.setWidth(30); button.setHeight(15); tr.addView(button); } root.addView(tr); } minitable.addView(root); setContentView(mRoot); } } test_inflate1.zip 반응형 저작자표시 비영리 변경금지 (새창열림)