0
제목과 마찬가지로 ImageView를 tableRow에 균등하게 퍼뜨리는 데 문제가 있습니다. 내 XML은 다음과 같습니다스프레드 이미지가 tablerow에 균등하게 표시됩니다.
for (int i = 0; i < 4; i++) {
tableRow = new TableRow(this);
tableRow.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT));
tableRow.setId(i + 1);
tableRow.setBackgroundResource(R.mipmap.shelfboard);
tableRow.setPadding(20, 0, 20, 0);
tableRow.setOnClickListener(thisvariable);
tableLayout.addView(tableRow);
}
이 지금은 같은 폭의 ImageViews의 다른 번호를 추가 할 : 활동 후
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<ProgressBar/>
<TextView/>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/progressBar">
<TableLayout
android:id="@+id/tableLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
</TableLayout>
</ScrollView>
는 동적 표는 다음과 같은 코드를 작성 시작 각 tableRow에 각 tableRow.
I 4 TableRows
- 1
- 2
- 가 tableRow 3
- 7 ImageViews 추가 tableRow 3 ImageViews 추가 tableRow 5 ImageViews 추가 tableRow 2 ImageViews 추가가 4
내 코드 :
for (int i = 0; i < adpList.size(); i++) {
int row = adpList.get(i).getShelfBoard();
if (row==1) {
int productsPerBoard = 2;
int width = (tableLayout.getWidth())/productsPerBoard;
TableRow.LayoutParams tlp = new TableRow.LayoutParams(width, TableRow.LayoutParams.MATCH_PARENT);
productPicture = new ImageView(this);
r = (TableRow) findViewById(row);
productPicture.setLayoutParams(tlp);
}
if (row==2) {
int productsPerBoard = 5;
int width = (tableLayout.getWidth())/productsPerBoard;
TableRow.LayoutParams tlp = new TableRow.LayoutParams(width, TableRow.LayoutParams.MATCH_PARENT);
productPicture = new ImageView(this);
productPicture.setBackgroundResource(R.drawable.border);
r = (TableRow) findViewById(row);
productPicture.setLayoutParams(tlp);
}
if (row==3) {
int productsPerBoard = 3;
int width = (tableLayout.getWidth())/productsPerBoard;
TableRow.LayoutParams tlp = new TableRow.LayoutParams(width, TableRow.LayoutParams.MATCH_PARENT);
productPicture = new ImageView(this);
r = (TableRow) findViewById(row);
productPicture.setLayoutParams(tlp);
}
if (row==4) {
int productsPerBoard = 7;
int width = tableLayout.getWidth()/productsPerBoard;
TableRow.LayoutParams tlp = new TableRow.LayoutParams(width, TableRow.LayoutParams.MATCH_PARENT);
productPicture = new ImageView(this);
r = (TableRow) findViewById(row);
productPicture.setLayoutParams(tlp);
}
productPicture.setBackgroundResource(R.mipmap.ic_launcher);
r.addView(productPicture);
불행히도 모든 행에는 두 장의 그림 만 있습니다. 항상 첫 번째 보드 너비가 필요합니다. 내 출력 : I는 각 행에 ImageViews의 다른 번호를 추가 할 수있는 방법
?