0

私は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); 
} 
+0

なぜグリッドビューを使用しないのですか? – tyczj

+0

@tyczj申し訳ありませんが、私はこれに多くの経験がありません。 – utdev

+0

https://developer.android.com/guide/topics/ui/layout/gridview.html – tyczj

答えて

0

は、このように構成された、あなたの内部成分を持っています外の方はRelativeLayout ViewGroupはあまり役に立たない

+0

答えに感謝して、私は外側のRelativeLayoutを削除し、xmlをあなたの提供するものに置き換えましたが、私はまだできません他のアイデアはそのまま残す – utdev

+0

はScroll View Top ViewGroupですか? – Pooya

+0

はいScrollViewがトップビューグループ – utdev

0

私がここに見る主な問題は、TableLayoutをカプセル化するLinearLayoutandroid:layout_height="match_parent"であることです。つまり、ScrollViewの内側の子は、親と同じ高さになり、スクロールしないレイアウトになります。

LinearLayoutを削除し、唯一の子としてTableLayoutを残してみませんか?その子の高さをandroid:layout_height="wrap_content"に設定することを忘れないでください。

ところで、大量のデータを表示するには、ListViewを使用することをおすすめします。

最後のこと:各レイアウト宣言にxml名前空間(xmlns:android="http://schemas.android.com/apk/res/android")を宣言する必要はありません。 )ルートエレメントの宣言が1つだけであれば問題ありません;

0

なぜ、recyclerviewを使用しないのですか? WSを消費するために改装する必要があります

+0

WSとはどういう意味ですか? – utdev

+0

Webサービス、APIからのデータ – Woz

関連する問題