title: java.lang.IllegalStateException: HorizontalScrollView can host only one direct child
body: <p>I want to realize the Gallery using HorizontalScrollView. But it throws java.lang.illegalStateException. The logcat hint that the HorizontalScrollView can host only one direct child. I only set one direct child - LinearLayout to it. I searched from the Internet, but haven't solved the problem. Hope anyone can help me. Belows are the code.</p>
  
  <p>xml</p>
  
  <pre><code>&lt;HorizontalScrollView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:padding="8dp"
      android:scrollbars="none"
      &gt;
  
      &lt;LinearLayout
         android:id="@+id/gallery_layout"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:orientation="horizontal"&gt;
      &lt;/LinearLayout&gt;
  
  &lt;/HorizontalScrollView&gt;
  </code></pre>
  
  <p>item xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:orientation="vertical"
      android:paddingTop="10dp"
      android:paddingLeft="8dp"
      android:paddingRight="8dp"
      android:paddingBottom="20dp"
      &gt;
  
      &lt;ImageView
          android:id="@+id/trend_item_imageview"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:paddingBottom="8dp"
          android:src="@drawable/gallery0"
          /&gt;
  
      &lt;TextView
          android:id="@+id/trend_item_textview"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="权利的游戏"
          android:textSize="16sp"
          /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>Fragment</p>
  
  <pre><code>public class DiscoverFragment extends Fragment {
  
      private int[] imageResources = {R.drawable.gallery0, R.drawable.gallery1, R.drawable.gallery2,
          R.drawable.gallery3, R.drawable.gallery4, R.drawable.gallery5};
  
      private String[] imageDescriptions = {"权利的游戏", "风吹的风景", "插画背景", "美食君", "吃", "你好四月"};
  
      private List&lt;TrendItem&gt; trendItemList;
      private LinearLayout galleryLayout;
  
      public DiscoverFragment() {
      // Required empty public constructor
      }
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
                           Bundle savedInstanceState) {
          // Inflate the layout for this fragment
          View view = inflater.inflate(R.layout.fragment_discover, container, false);
          ButterKnife.bind(this, view);
          galleryLayout = ButterKnife.findById(view, R.id.gallery_layout);
          initData();
          setView();
          return view;
      }
  
      private void initData(){
          trendItemList = new ArrayList&lt;&gt;();
          for (int i = 0; i &lt; imageResources.length; i++){
              TrendItem trendItem = new TrendItem();
              trendItem.setImageResource(imageResources[i]);
              trendItem.setText(imageDescriptions[i]);
              trendItemList.add(trendItem);
          }
      }
  
      private void setView(){
          for (int i = 0; i &lt; trendItemList.size(); i++){
              LayoutInflater inflater = LayoutInflater.from(getContext());
              View view = inflater.inflate(R.layout.trend_item, galleryLayout, false);
              ImageView trendItemImageView = ButterKnife.findById(view, R.id.trend_item_imageview);
              TextView trendItemTextView = ButterKnife.findById(view, R.id.trend_item_textview);
              trendItemImageView.setImageResource(trendItemList.get(i).getImageResource());
              trendItemTextView.setText(trendItemList.get(i).getText());
              galleryLayout.addView(view);
          }
      }
  }
  </code></pre>