0
我想將3個HorizontalScrollView添加到一個片段中。我已經成功實施了一個,但是當我試圖將另一個horizontalscrollview
分成相同的片段時,我得到一個錯誤,HorizontalScrollView
只支持一個孩子。所以,我用XML創建了另一個horizontalscrollview
。我創建了第二個線性佈局,並將新的圖像查看器ID傳遞給了第二個線性佈局,但它不會顯示在屏幕上。如何將3個HorizontalScrollViews添加到一個片段中?
這裏是XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="fill_parent"android:layout_height="fill_parent" >
<HorizontalScrollView
android:orientation="horizontal"
android:layout_width="800px"
android:id="@+id/horizontalScroll"
android:background="#C6D7D2" android:layout_height="600px">
<LinearLayout
android:id="@+id/container"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</LinearLayout>
</HorizontalScrollView>
<HorizontalScrollView
android:orientation="horizontal"
android:layout_width="800px"
android:id="@+id/horizontalScroll2"
android:background="#C6D7D2"
android:layout_height="600px">
<LinearLayout
android:id="@+id/container2"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
這裏是Java代碼片段代碼
public class FevFragment extends SherlockFragment{
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.cfragment, container, false);
}
@Override
public void onStart() {
super.onStart();
/** Setting the multiselect choice mode for the listview */
initfrag();
}
private void initfrag() {
LinearLayout linearlayout1 = (LinearLayout)getView().findViewById(R.id.container);
LinearLayout linearlayout2 = (LinearLayout)getView().findViewById(R.id.container2);
for (int i = 0; i < 15; i++) {
ImageView iv = new ImageView(getActivity());
iv.setPadding(5, 55, 5, 5);
iv.setImageResource(R.drawable.test_play_image);
linearlayout1.addView(iv, 260, 260);
ImageView iv2 = new ImageView(getActivity());
iv2.setPadding(5, 255, 5, 5);
iv2.setImageResource(R.drawable.test_play_image);
linearlayout2.addView(iv2, 100, 100);
TextView tv = new TextView(getActivity());
tv.setText("testing");
tv.setPadding(5, 55, 5, 5);
linearlayout1.addView(tv, 100, 100);
}
} }
是的明白了..現在我得到了2張圖片view..can你請告訴我如何對齊textview下面的圖片? –
檢查這個SO問題http://stackoverflow.com/questions/2305395/laying-out-views-in-relativelayout-programmatically。我認爲_Meymann_答案就是你要找的。接受我的回答;) – sinisha
謝謝@sinisha只需一個幫助請幫助..我通過Json解析獲取圖像鏈接,所以你可以建議我哪一個是最好的數據結構來存儲該URL和圖像名稱在一起(arraylist ,hashmap)...就像當我點擊圖像時,它會顯示特定的圖像名稱,並將您重定向到該URL ..任何解析和存儲的例子,並將其傳遞給horizontalscrolview? –