Hallo zusammen,
ich versuche in einen GridView (um genau zu sein: DraggableGridView) Layouts zu generieren (Hab davor noch nie ein Layout über code erstellt) Basierend auf die Anzahl der Einträge in der Datenbank). Die App stützt auch nicht App, eigentlich macht sie auch fast alles was sie soll. Also das RelativeLayout hat die richtige Größe und auch der Hintergund stimmt.
Mein Layout soll so aufgebaut sein (xml Vorbild):
QuoteDisplay More
<RelativeLayout
android:layout_width="150dp"
android:layout_height="150dp"
android:background="@drawable/ic_contact_picture_2">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Small Text"
android:id="@+id/textView" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Small Text"
android:id="@+id/textView2" />
</LinearLayout>
</RelativeLayout>
[Blocked Image: http://s7.directupload.net/images/140613/temp/oxkjl9sl.png]
hier der code:
QuoteDisplay More
for (int i = 0; i < names.length; i++) {
RelativeLayout relativeLayout = new RelativeLayout(getActivity());
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(150, 150);
relativeLayout.setLayoutParams(layoutParams);
relativeLayout.setBackground(new BitmapDrawable(getResources(), getThumb(cursor.getLong(0))));
RelativeLayout.LayoutParams layoutParams2 = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
layoutParams2.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
// ab hier geht es nicht mehr
LinearLayout linearLayout = new LinearLayout(getActivity());
linearLayout.setOrientation(LinearLayout.HORIZONTAL);
linearLayout.setGravity(Gravity.BOTTOM);
TextView textView = new TextView(getActivity());
textView.setTextAppearance(getActivity(), android.R.style.TextAppearance_Small);
textView.setText("TEST");
textView.setTextSize(10);
linearLayout.addView(textView);
TextView textView2 = new TextView(getActivity());
textView2.setTextAppearance(getActivity(), android.R.style.TextAppearance_Small);
textView2.setText("TEST2");
textView2.setTextSize(10);
linearLayout.addView(textView2);
relativeLayout.addView(linearLayout, layoutParams2);
dgv.addView(relativeLayout);
cursor.moveToNext();
}
Sieht wer den/die Fehler? Danke schon mal im voraus