C
chnooorzi
Neues Mitglied
- 0
Hallo
Ich habe eine Frage.
Ich habe in XML ein GridLayout vorbereitet. Ist es möglich dieses Gridlayout dynamisch z.b einer ScrollView hinzuzufügen?
Wie man ein GridLayout in einer Java-Klasse definiert weiss ich, aber ich frage mich ob es nicht sinnvoller ist, das LAyout in einer XML-Datei zu bestimmen und dieses dann sozusagen als Template ein paar Mal der ScrollView hinzuzufügen.
HIer der XML-COde:
Die ScrollView ist in einem Fragment:
ScrollView scrollView = (ScrollView) getActivity().findViewById(R.id.scrollViewTest);
<----- HIer möchte ich z.b 4 mal das GridLayout einfügen ----->
Danke für eure Hilfe!
Gruss chnooorzi
EDIT: HAbe die Lösung gefunden. Mit:
View child = inflater.inflate(R.layout.test_item, null);
kann eine View aus dem XML erzeugt werden. Diese kann dann ganz normal dem LinearLayout hinzugefügt werden.
Ich habe eine Frage.
Ich habe in XML ein GridLayout vorbereitet. Ist es möglich dieses Gridlayout dynamisch z.b einer ScrollView hinzuzufügen?
Wie man ein GridLayout in einer Java-Klasse definiert weiss ich, aber ich frage mich ob es nicht sinnvoller ist, das LAyout in einer XML-Datei zu bestimmen und dieses dann sozusagen als Template ein paar Mal der ScrollView hinzuzufügen.
HIer der XML-COde:
Code:
<?xml version="1.0" encoding="utf-8"?>
<GridLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#ff4afff3"
android:id="@+id/gridLayoutItem">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="@+id/textView2"
android:layout_row="0"
android:layout_column="0"
android:layout_margin="5dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Small Text"
android:id="@+id/textView"
android:layout_column="0"
android:layout_row="1"
android:layout_margin="5dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Small Text"
android:id="@+id/textView3"
android:layout_column="0"
android:layout_row="2"
android:layout_margin="5dp" />
</GridLayout>
Die ScrollView ist in einem Fragment:
ScrollView scrollView = (ScrollView) getActivity().findViewById(R.id.scrollViewTest);
<----- HIer möchte ich z.b 4 mal das GridLayout einfügen ----->
Danke für eure Hilfe!
Gruss chnooorzi
EDIT: HAbe die Lösung gefunden. Mit:
View child = inflater.inflate(R.layout.test_item, null);
kann eine View aus dem XML erzeugt werden. Diese kann dann ganz normal dem LinearLayout hinzugefügt werden.
Zuletzt bearbeitet: