Ich versuche, ein einfaches Raster-Layout zu erstellen, die eine Miniaturansicht mit einem Kommentar unten, damit er in einer 2-Säule und unendliche Reihe Tabelle (siehe Bild unten)Mit GridLayout in Android, wie kann ich es einrichten, so dass jedes Element, das ich hinzufüge, richtig platziert ist (unbegrenzte Anzahl)?
Jedes Mal, wenn ein Bild aufgenommen werden Platz ist Es wird dem Rasterlayout hinzugefügt, aber alle Parameter, die ich ausprobiert habe, geben entweder einen Fehler nach dem 3. Bild oder werden nur falsch angezeigt.
{CODE}
Dieser Teil meines Code erstellt ein Miniaturbild mit Größe 400.400 aus einem Bild nur genommen und dann zusammen mit den Grid Parametern an die Gridlayout-Ansicht hinzugefügt.
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
//setups
setResult(resultCode);
GridLayout templayout = (GridLayout) findViewById(R.id.pictureLayout);
int col = 2;
int row = 2;
templayout.setColumnCount(col);
templayout.setRowCount(row);
String path = tempPicture[4];
ImageView image = new ImageView(this);
Bitmap thumb = createThumbnailFromBitmap(path, 400, 400);
image.setImageBitmap(thumb);
image.setLayoutParams(new android.view.ViewGroup.LayoutParams(400,400));
GridLayout.Spec rowSpan = GridLayout.spec(GridLayout.UNDEFINED, 1);
GridLayout.Spec colSpan = GridLayout.spec(GridLayout.UNDEFINED, 2);
GridLayout.LayoutParams gridParam = new GridLayout.LayoutParams(rowSpan, colSpan);
templayout.addView(image, gridParam);
temp = Integer.valueOf(tempPicture[0]);
image.setId(temp);
image.setTransitionName(path);
image.setOnClickListener(ClickPic(image));
addToTempList(tempPicture);
//This creates a edit text just below the newly created thumbnail
createEditableComment(tempPicture[0], templayout);
}
Die createComment Methode, um nach der Erstellung unter dem Vorschaubild wird gerade hinzugefügt (manchmal unten)
void createEditableComment(String picId, GridLayout belowpic){
EditText comment = new EditText(this);
comment.setTextSize(20);
comment.setId(Integer.valueOf(picId));
comment.setLayoutParams(new android.view.ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
pictureComments.add(comment);
belowpic.addView(comment);
}
mein xml Hier ist nur verursachen. Prost
<GridLayout
android:orientation="vertical"
android:id="@+id/pictureLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:columnCount="2">
</GridLayout>
Sie quesition ist nicht klar. –