0

I want to add 3 HorizontalScrollView into one fragments. I have successfully implemented one but when I tried to implement another horizontalscrollview into same fragments, then I got an error that HorizontalScrollViews support only one child. So, I created another horizontalscrollview in XML. I have created a second linearlayout and passed a new imageviewer ID to that second linearlayout, but it won't show on screen.

Here is the 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>

and here is java fragment code

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);
        }
}  }
jonsca
  • 10,218
  • 26
  • 54
  • 62
Swap-IOS-Android
  • 4,363
  • 6
  • 49
  • 77

1 Answers1

0

Read the documentation

A HorizontalScrollView is a FrameLayout, meaning you should place one child in it containing the entire contents to scroll; this child may itself be a layout manager with a complex hierarchy of objects. A child that is often used is a LinearLayout in a horizontal orientation, presenting a horizontal array of top-level items that the user can scroll through

In your first LinearLayout (you didn't declare id) use this attribute

android:orientation="vertical"
sinisha
  • 1,013
  • 13
  • 30
  • yes got it..now i got 2 image view..can you please tell me how can i align textview below image? – Swap-IOS-Android Nov 06 '12 at 13:46
  • 1
    Check this SO question http://stackoverflow.com/questions/2305395/laying-out-views-in-relativelayout-programmatically. I think _Meymann_ answer is what you are looking for. Accept my answer ;) – sinisha Nov 06 '12 at 14:01
  • thanks @sinisha for the help just one more help please .. i am fetching image link by Json parsing so could you please suggest me which one is best data structure to store that url and image name both together(arraylist , hashmap )...like when i click on image it will display particular that image name and redirect you into that URL..any example of parsing and storing and passing it to horizontalscrolview? – Swap-IOS-Android Nov 06 '12 at 14:17