저는 LinearLayout 대안에 가깝지만, 이처럼 짜증나는 것은 아닙니다. 사물의 유연성을 극대화하기 위해 정의 된 행 헤더 만있는 TableLayout xml을 정의했습니다. 다음으로 "행 템플릿"을 정의하는 별도의 TableRow xml을 생성했습니다. Javacode에서는 TableRow를 서브 클래 싱했습니다. 생성자에서 루트 (서브 클래 싱 된 클래스)에 첨부하기 위해 tablerow 템플릿을 부 풀립니다.레이아웃 문제 tablerow 및 inflating xml tablerow
글쎄, 지금까지는 좋아. 테이블이 채워지면 headerrow는 괜찮지 만 다른 행은 NOT입니다. 서로 다른 방식으로 배치 된 것처럼 보입니다. 두 열이 예상대로 전체 너비를 채우지 않아서 coluomns가 서로 올바르게 정렬되지 않습니다.
누구나이 부분을 밝힐 수있는 사람은 누구입니까? 나는 많은 솔루션을 시도했지만 아무 것도 작동하지 않습니다.
헤더 행이있는 TableLayout을
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true" >
<HorizontalScrollView
android:id="@+id/horizontalScrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true" >
<TableLayout
android:id="@+id/zone_table"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:stretchColumns="*" >
<TableRow
android:id="@+id/tableRow1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="fill_horizontal"
android:clipToPadding="false" >
<TextView
android:layout_width="0dip"
android:layout_weight="0.8"
android:background="#ffcccccc"
android:text="Zonename"
android:textColor="@android:color/black" />
<TextView
android:layout_width="0dip"
android:layout_weight="0.2"
android:background="#ffcccc00"
android:gravity="right"
android:text="Antall"
android:textColor="@android:color/black" />
</TableRow>
</TableLayout>
</HorizontalScrollView>
</ScrollView>
"기타"비정상적 행
<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/zonetablerow"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<TextView
android:id="@+id/zonerow_name"
android:layout_width="0dip"
android:layout_weight="0.8"
android:background="#ffcccccc"
android:textSize="18dp" />
<TextView
android:id="@+id/zonerow_invcount"
android:layout_width="0dip"
android:layout_gravity="right"
android:layout_weight="0.2"
android:background="#ffcccc00"
android:textSize="18dp" />
</TableRow>
클래스 TableRow 그것은 무엇처럼 보이는 것은 당신이 tablerow을 확장하고 있다는 점이다
을public class ZoneRow extends TableRow {
private ZoneInventoryDAO dao = null;
private int inventoryCount = 0;
public ZoneRow(Context ctx, ZoneInventoryDAO dao) {
this(ctx, dao, 0);
}
public ZoneRow(Context ctx, ZoneInventoryDAO dao, int inventoryCount) {
super(ctx);
setWeightSum(1.0f);
this.dao = dao;
this.inventoryCount = inventoryCount;
doLayout();
}
private void doLayout() {
// XML layouten settes med zonerow som parent (se:
// http://developer.android.com/resources/articles/layout-tricks-merge.html)
View v = LayoutInflater.from(getContext()).inflate(R.layout.zonerow,
this, true);
TextView t = (TextView) findViewById(R.id.zonerow_name);
TextView cnt = (TextView) findViewById(R.id.zonerow_invcount);
t.setText(dao.getZoneAlias());
cnt.setText(String.valueOf(inventoryCount));
}
public void incInventory() {
inventoryCount++;
}
public ZoneInventoryDAO getDAO() {
return dao;
}
}