how to add multiple child in horizontal scroll view in android

自古美人都是妖i 提交于 2019-12-24 06:45:53

问题


In this application i tag the data using json parsing and binding the data using list adapter and i was add the heading for data in static using table layout, when i scroll horizontally the data scroll with heading but horizontal scroll view only allowed to only one child, i need two layout in single horizontal scroll view. please help

my xml is

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     android:background="#ffffff"
     android:orientation="vertical">
<!-- Main ListView Always give id value as list(@android:id/list) -->
   <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
         android:layout_width="fill_parent"
         android:layout_height="wrap_content"
         android:background="#ffffff"
         android:orientation="horizontal">

     <TableRow
         android:id="@+id/tableRow1"
         android:scrollbarAlwaysDrawHorizontalTrack="true"
         android:layout_height="wrap_content"
         android:layout_width="match_parent">

         <TextView
            android:id="@+id/TextView2"
            android:text="GRPName"
            android:background="#A513FF"

            android:textColor="#000000"
            android:layout_width="150dp"
            android:padding="3dip"
            android:gravity="left"/>

         <TextView
            android:id="@+id/TextView3" android:text="NAME"
            android:background="#A513FF"
            android:textColor="#000000"
            android:layout_width="100dp"
            android:padding="3dip" android:gravity="left"/>

         <TextView
            android:id="@+id/TextView4" android:text="MRP"
            android:background="#A513FF"
            android:textColor="#000000"
            android:layout_width="100dp"
            android:padding="3dip" android:gravity="left"/>

         <TextView
            android:id="@+id/TextView5" android:text="QNT"
            android:background="#A513FF"
            android:textColor="#000000"
            android:layout_width="100dp"
            android:padding="3dip" android:gravity="left"/>

         <TextView
            android:id="@+id/TextView2" android:text="ID"
            android:background="#A513FF"
            android:textColor="#000000"
            android:layout_width="100dp"
            android:padding="3dip"
            android:gravity="left"/>

        <TextView
            android:id="@+id/TextView3" android:text="NAME"
            android:background="#A513FF"
            android:textColor="#000000"
            android:layout_width="100dp"
            android:padding="3dip" android:gravity="left"/>

    </TableRow>
  </LinearLayout>

  <HorizontalScrollView
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:id="@+id/horizontalScrollView">
    <ListView
            android:id="@android:id/list"
            android:smoothScrollbar="true"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"/>
  </HorizontalScrollView>
</LinearLayout>

I need to table layout in the horizontal scroll view


回答1:


You have to put one layout as a scrollviews child, then put every other views in that child and it should work fine.

Like this way:

<HorizontalScrollView
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:id="@+id/horizontalScrollView">

    <LinearLayout ... >
    ... insert your views in here
    </LinearLayout>
</HorizontalScrollView>


来源:https://stackoverflow.com/questions/17486816/how-to-add-multiple-child-in-horizontal-scroll-view-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!