Ich bin dynamisch Erstellen von Tabellenzeilen und Textansichten von meinen JSON-Daten, die ich von einer API bekomme. Momentan werden die Daten korrekt angezeigt, aber irgendwie funktioniert meine Scrollview nicht. Es scrollt nicht. Ich habe eine ScrollView hinzugefügt, aber ich vermute, dass ich dort etwas falsch mache.Android Scrollview funktioniert nicht auf dynamischen Inhalt
Mein Xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ScrollView android:id="@+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TableLayout
android:id="@+id/tlMarksTable"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</TableLayout>
</LinearLayout>
</ScrollView>
</RelativeLayout>
Und der Teil, in dem ich die Ansichten erzeugen sieht wie folgt aus:
jsonArray = new JSONArray(result);
TableRow tableRow = new TableRow(context);
setContentView(tableRow);
tableRow.setOrientation(LinearLayout.VERTICAL);
for(int i= 0; i < jsonArray.length(); i++) {
JSONObject jsonobject = jsonArray.getJSONObject(i);
String id = jsonobject.getString("id");
String content = jsonobject.getString("content");
TextView textView = new TextView(context);
textView.setText(content);
if (Build.VERSION.SDK_INT < 23) {
textView.setTextAppearance(getApplicationContext(), R.style.boldText);
} else {
textView.setTextAppearance(R.style.boldText);
}
textView.setBackgroundResource(R.color.highlightedTextViewColor);
textView.setPadding(10, 10, 10, 10);
textView.setTextSize(getResources().getDimension(R.dimen.joke_content_font_size));
tableRow.addView(textView);
}
Warum verwenden Sie nicht einfach eine Gridview? – tyczj
@tyczj Tut mir leid, ich habe nicht viel Erfahrung in diesem, könnten Sie weiter erklären, was Sie meinen? – utdev
https://developer.android.com/guide/topics/ui/layout/gridview.html – tyczj