私はAPIから取得したJSONデータからテーブル行とテキストビューを動的に作成しています。現在のところ、データは正しく表示されますが、何とかスクロールビューが機能しません。スクロールしません。私はScrollViewを追加しましたが、私はそこに何か間違っていると思います。Androidのscrollviewは動的コンテンツでは機能しません
私の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>
そして、私はビューを生成する部分は次のようになりますによって
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TableLayout
android:id="@+id/tlMarksTable"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</TableLayout>
</LinearLayout>
:
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);
}
なぜグリッドビューを使用しないのですか? – tyczj
@tyczj申し訳ありませんが、私はこれに多くの経験がありません。 – utdev
https://developer.android.com/guide/topics/ui/layout/gridview.html – tyczj