问题
I have a ListView
that I load data into it from a data table with about 10 columns, so I need the user to be able to scroll horizontally to see all the data. Now I want to put Columns on top of the ListView
, but inside the Horizontal Scroll. Unfortunately I can't figure out how to put the TextBoxes
on top of the ListView
, but inside the Horizontal scroll. It always push ListBox
in the same level at the TextBoxes
. It is even possible to do this?
My XML code is below:
<HorizontalScrollView
android:id="@+id/horizontalScrollView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/imageView2" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="527dp"
android:orientation="horizontal" >
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50sp"
android:layout_weight="1"
android:headerDividersEnabled="true" >
</ListView>
<TextView
android:id="@+id/code"
android:layout_width="110sp"
android:layout_height="wrap_content"
android:layout_marginLeft="0dp"
android:layout_marginStart="1dp"
android:layout_alignParentTop="true"
android:maxLines="1"
android:text="@string/lChangedTime"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="17sp" />
<TextView
android:id="@+id/manufacturer"
android:layout_width="70sp"
android:layout_height="wrap_content"
android:layout_marginLeft="11dp"
android:maxLines="1"
android:text="manufacturer"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="17sp" />
<TextView
android:id="@+id/name"
android:layout_width="200sp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="11dp"
android:layout_toRightOf="@+id/manufacturer"
android:maxLines="1"
android:text="@string/lCustomerName"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="20sp" />
<TextView
android:id="@+id/visc40"
android:layout_width="50sp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="11dp"
android:layout_toRightOf="@+id/name"
android:maxLines="1"
android:text="visc40"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="17sp" />
<TextView
android:id="@+id/visc100"
android:layout_width="50sp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="11dp"
android:layout_toRightOf="@+id/visc40"
android:maxLines="1"
android:text="visc100"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="17sp" />
</LinearLayout>
</HorizontalScrollView>
回答1:
If I understand you correctly then you need to nest your text views in another layout.
let me show you what I mean
<HorizontalScrollView
android:id = "@+id/horizontalScrollView1"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:layout_alignParentLeft = "true"
android:layout_alignParentRight = "true"
android:layout_below = "@+id/imageView2">
<LinearLayout
android:layout_width = "match_parent"
android:layout_height = "527dp"
android:orientation = "vertical">
<LinearLayout
android:layout_width = "match_parent"
android:layout_height = "wrap_content"
android:orientation = "horizontal">
<TextView
android:id = "@+id/code"
android:layout_width = "110sp"
android:layout_height = "wrap_content"
android:layout_marginLeft = "0dp"
android:layout_marginStart = "1dp"
android:layout_alignParentTop = "true"
android:maxLines = "1"
android:text = "@string/lChangedTime"
android:textAppearance = "?android:attr/textAppearanceLarge"
android:textSize = "17sp"/>
<TextView
android:id = "@+id/manufacturer"
android:layout_width = "70sp"
android:layout_height = "wrap_content"
android:layout_marginLeft = "11dp"
android:maxLines = "1"
android:text = "manufacturer"
android:textAppearance = "?android:attr/textAppearanceLarge"
android:textSize = "17sp"/>
<TextView
android:id = "@+id/name"
android:layout_width = "200sp"
android:layout_height = "wrap_content"
android:layout_alignParentTop = "true"
android:layout_marginLeft = "11dp"
android:layout_toRightOf = "@+id/manufacturer"
android:maxLines = "1"
android:text = "@string/lCustomerName"
android:textAppearance = "?android:attr/textAppearanceLarge"
android:textSize = "20sp"/>
<TextView
android:id = "@+id/visc40"
android:layout_width = "50sp"
android:layout_height = "wrap_content"
android:layout_alignParentTop = "true"
android:layout_marginLeft = "11dp"
android:layout_toRightOf = "@+id/name"
android:maxLines = "1"
android:text = "visc40"
android:textAppearance = "?android:attr/textAppearanceLarge"
android:textSize = "17sp"/>
<TextView
android:id = "@+id/visc100"
android:layout_width = "50sp"
android:layout_height = "wrap_content"
android:layout_alignParentTop = "true"
android:layout_marginLeft = "11dp"
android:layout_toRightOf = "@+id/visc40"
android:maxLines = "1"
android:text = "visc100"
android:textAppearance = "?android:attr/textAppearanceLarge"
android:textSize = "17sp"/>
</LinearLayout>
<ListView
android:id = "@+id/listView1"
android:layout_width = "match_parent"
android:layout_height = "wrap_content"
android:layout_marginTop = "50sp"
android:layout_weight = "1"
android:headerDividersEnabled = "true">
</ListView>
</LinearLayout>
</HorizontalScrollView>
来源:https://stackoverflow.com/questions/16701824/listview-with-header-inside-a-horizontal-scroll