5

14個のフィールドを含むカスタムリストビューがあります。次のようなものです。

field1 field2 field3 field4 field5 field6 field7 field8 field9 field10 field11 field12field13field14。明らかな問題は、画面上のすべてのフィールドを収めることができないということです。リストビュー全体を水平方向にスクロールさせたいので、5〜6個のフィールドしか表示できず、ユーザーが水平方向にスクロールすると、それらの残りを見ることができるようになります。垂直方向と水平方向の両方にスクロールするリストビューを表示することはできますか?

4

4 に答える 4

10

次のように、水平スクロールビュー、スケルトン内にリストビューを作成するだけです。

<HorizontalScrollView ...........>
    <LinearLayout ......>
        <LinearLayout ......>
        //List View Titles will be here
        </LinearLayout>

        <ListView ........ android:layout_weight="1" />

    </LinearLayout>
</HorizontalScrollView>

ここで、スクロールできないタイトルをリストビューに表示する必要がある場合は、前述のように別のレイアウトで追加し、 layout_weight属性を設定することを忘れないでください。

于 2012-12-04T09:38:32.693 に答える
0

このリンクに示されているように、VerticalScrollViewの子であるHorizo​​ntalScrollViewが必要です。

于 2012-12-04T09:28:15.123 に答える
0

水平リストビューを実装するための最も簡単で簡単な方法。

Horizo​​natalscroll.xml

 <?xml version="1.0" encoding="utf-8"?>
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scroll"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fadeScrollbars="false"
android:background="@color/list_item_bg_color">

 </HorizontalScrollView>

horizo​​ntal_list.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/horizontal_outer_layout"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_margin="0dp"
android:background="@drawable/rect_border_box"
android:orientation="vertical" >



    <TextView
        android:id="@+id/text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
         />
   </Linearlayout>

Javaコード:

      LinearLayout parent = (LinearLayout) getLayoutInflater().inflate(
            R.layout.observation_detail_parent_layout, null);
      Linearlayout child= null;


     //iterate views upto you adapater count.
      for(int i=0;i<14;i++){
      child = (LinearLayout) getLayoutInflater().inflate(
                    R.layout.horizontal_list, null);

        //set your views specified in horizontal_list.xml

      TextView text = (TextView) findViewById(R.id.text);
      text.setText("your text");
      parent.addView(child);
    }
于 2012-12-04T10:13:19.123 に答える
0

リストビューはすでに垂直スクロールをサポートしているので、水平スクロールをサポートする必要があります。以下のコードは私にとっては完全にうまく機能しました。「重みが1」であっても、リストビューの「高さを0dp」にしないように注意してください。Horizo​​ntalScrollViewは高さをゼロとし、リストビューのアイテムを描画しないためです。

<?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/table_view"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >

        <TextView
            android:layout_width="58dp"
            android:layout_height="fill_parent"
            android:gravity="center"
            android:text="header"
            android:textColor="@android:color/black" />

        <HorizontalScrollView
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" >

            <ListView
                android:id="@+id/mylist"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_weight="1" >
            </ListView>
        </HorizontalScrollView>
    </LinearLayout>
于 2015-09-17T19:36:07.700 に答える