기본적으로 테이블에 행을 추가하려고하는데, 프로그래밍 방식으로이 작업을 수행해야합니다.Android Relativelayout 프로그래밍 방식으로
원하는 콘텐츠를 추가 할 수는 있지만 정확하게 원하는 콘텐츠는 추가 할 수 없습니다.
예를 들어, 오른쪽에 단추 편집 텍스트 단추가있는 왼쪽에 텍스트보기가 필요합니다.
http://s16.postimage.org/nluqthuut/Untitled_1.png :
는 기본적으로 나는 아래의 이미지처럼합니다.
또한 텍스트 뷰에 너비와 너비가 싶지 않습니다. 어쨌든 여기
내가 지금까지 변경 한 내용은 다음과 같습니다
XML은 :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:padding="5dp" xmlns:android="http://schemas.android.com/apk/res/android">
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<Button
android:id="@+id/btnOutstandingJob"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="Outstanding Job" />
<Button
android:id="@+id/btnVanStock"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="Van Stock" />
<Button
android:id="@+id/btnRegister"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="Register User" />
</LinearLayout>
</ScrollView>
<RelativeLayout
android:id="@+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<Button
android:id="@+id/btnLogout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginTop="5dp"
android:text="Log Out" />
</RelativeLayout>
</LinearLayout>
자바 :
TableLayout table = (TableLayout) findViewById(R.id.tableLayout1);
TableRow row = new TableRow(vanstock.this);
RelativeLayout RowLayout = new RelativeLayout(vanstock.this);
RowLayout.setId(99);
TextView lblItem = new TextView(vanstock.this);
lblItem.setId(1);
lblItem.setText("ddfsgsdfgs");
RelativeLayout.LayoutParams lblitemParam = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
lblitemParam.addRule(RelativeLayout.CENTER_VERTICAL,
RelativeLayout.TRUE);
lblitemParam.addRule(RelativeLayout.ALIGN_PARENT_LEFT,
RelativeLayout.TRUE);
lblItem.setLayoutParams(lblitemParam);
RowLayout.addView(lblItem);
Button btnPlus = new Button(vanstock.this);
btnPlus.setId(4);
btnPlus.setText("+");
btnPlus.setWidth(40);
RelativeLayout.LayoutParams btnPlusParams = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
btnPlusParams.addRule(RelativeLayout.ALIGN_PARENT_TOP,
RelativeLayout.TRUE);
btnPlusParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT,
RelativeLayout.TRUE);
btnPlus.setLayoutParams(btnPlusParams);
RowLayout.addView(btnPlus);
EditText txtItem = new EditText(vanstock.this);
txtItem.setId(3);
txtItem.setWidth(40);
RelativeLayout.LayoutParams txtItemParams = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
txtItemParams.addRule(RelativeLayout.ALIGN_PARENT_TOP,
RelativeLayout.TRUE);
txtItemParams.addRule(RelativeLayout.LEFT_OF, btnPlus.getId());
txtItem.setLayoutParams(txtItemParams);
RowLayout.addView(txtItem);
Button btnMinus = new Button(vanstock.this);
btnMinus.setId(2);
btnMinus.setText("-");
btnMinus.setWidth(40);
RelativeLayout.LayoutParams btnMinusParams = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
btnMinusParams.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE);
btnMinusParams.addRule(RelativeLayout.LEFT_OF, txtItem.getId());
btnPlus.setLayoutParams(btnMinusParams);
RowLayout.addView(btnPlus);
row.addView(RowLayout);
table.addView(row, new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
나는 등 검색을 시도했지만 한 나는 아직도 할 수 없습니다 제대로 작동하도록하십시오. 어떤 도움을 주시면 감사하겠습니다!
난 당신이 너무 복잡하게 만드는 것 같아요. 연결된 이미지와 같은 구조를 만들면 ListView를 xml 파일에서 부풀려진 행과 함께 사용하게됩니다. 이 방법을 사용하면 모든 GUI 작업을 XML로 정의 할 수 있으며 Java로 할 수있는 몇 가지 세부 작업 만 수행하게됩니다. –