4
我從webservice
加載一些新網站我想將它們添加到HorizontalScrollView
。Android horizontalscrollview。實用添加視圖
在iOS上,我會通過循環播放我的新聞內容,然後將文本標籤作爲子視圖添加到ScrollView
。我試圖在android中做類似的事情,但我似乎無法讓它正常工作。無論我做什麼,這些項目都在下面列出。
繼承人我的代碼添加觀點:
public void setupViews(ArrayList<News> news)
{
HorizontalScrollView scrollView = (HorizontalScrollView) getView().findViewById(R.id.horizontalScrollView);
LinearLayout layout = (LinearLayout) getView().findViewById(R.id.linearLayout);
for(int i = 0; i < news.size(); i ++)
{
News newsItem = news.get(i);
TextView head = new TextView(this.getActivity());
head.setText(newsItem.getHead());
head.setId(100+i);
layout.addView(head);
}
}
的XML看起來是這樣的:
<HorizontalScrollView
android:layout_width="fill_parent"
android:layout_height="150dp"
android:id="@+id/horizontalScrollView" android:layout_gravity="center"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:id="@+id/linearLayout">
</LinearLayout>
</HorizontalScrollView>
這可能是值得指出的是,我是一個片段內這樣做..
這正是他在做的:) – Carnal 2012-07-17 09:40:12
他只需要設置orientation =「horizontal」 – Carnal 2012-07-17 09:41:38
我需要android:orientation =「horizontal」才能工作。愚蠢的我,謝謝! – 2012-07-17 09:41:56