Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/sharepoint/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android layout 使用布局权重等间距的自定义listview_Android Layout_Android Listview_Horizontalscrollview_Android Layout Weight - Fatal编程技术网

Android layout 使用布局权重等间距的自定义listview

Android layout 使用布局权重等间距的自定义listview,android-layout,android-listview,horizontalscrollview,android-layout-weight,Android Layout,Android Listview,Horizontalscrollview,Android Layout Weight,我正在使用一个自定义的listview,它有6个字段,所以我在每个字段中使用了带权重的水平滚动视图,以获得字段之间所需的间距` <HorizontalScrollView android:id="@+id/horizontalScrollView" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_alignParentTop="tr

我正在使用一个自定义的listview,它有6个字段,所以我在每个字段中使用了带权重的水平滚动视图,以获得字段之间所需的间距`

<HorizontalScrollView
    android:id="@+id/horizontalScrollView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentTop="true" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="30dp"
            android:background="#898ea0"
            android:orientation="horizontal"
            android:weightSum="11" >

            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="15dp"
                android:layout_weight="2"
                android:text="Name" />

            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:layout_weight="2"
                android:text="Site Name" />

            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:layout_weight="1.5"
                android:text="Plot No" />

            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:layout_weight="2.3"
                android:text="Booking Id" />

            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:layout_weight="1.6"
                android:text="Booking Date" />

            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:layout_weight="1.6"
                 android:layout_marginRight="8dp"
                android:text="Cancel Date" />
        </LinearLayout>


            <ListView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:id="@+id/cancel_booking_listView"
                android:background="#163330">

            </ListView>
    </LinearLayout>
</HorizontalScrollView>

`

在listview行项目中,我使用了所有具有相同权重的字段,但也无法在字段之间获得相等的间距。这是我的自定义行列表代码`

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:background="#eee"
        android:orientation="horizontal"
        android:weightSum="11" >

        <TextView
            android:id="@+id/cb_custmrnameTv"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="8dp"
            android:layout_weight="2"
            android:text="Name" />

        <TextView
            android:id="@+id/cb_siteNameTv"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_weight="2"
            android:text="Site Name" />

        <TextView
            android:id="@+id/cb_plotNoTv"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_weight="1.5"
            android:text="Plot No" />

        <TextView
            android:id="@+id/cb_bookingIdTv"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_weight="2.3"
            android:text="Booking Id" />

        <TextView
            android:id="@+id/cb_bookingDateTv"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_weight="1.6"
            android:text="Booking Date" />

        <TextView
            android:id="@+id/cb_cancelDateTv"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_weight="1.6"
            android:layout_marginRight="5dp"
            android:text="Cancel Date" />
    </LinearLayout>
</HorizontalScrollView>

` 为了更好地理解,这里是我得到的视图的屏幕截图。你们可以看到这里每一行都有自己的间距

我需要在所有字段之间实现相等的间距。 有什么办法解决这个问题吗?

试着用

android:layout_width="match_parent"
在文本视图字段中。
此外,您可能需要使用表格布局以获得适当的间距。

我解决了这个问题,为listview使用了一个自定义标题视图,该视图具有与自定义行列表相同的字段数和权重,并从主布局中删除了字段。 我的Cusotmer行列表标题视图是:`

<HorizontalScrollView
    android:id="@+id/horizontalScrollView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentTop="true" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="30dp"
        android:orientation="horizontal"
        android:weightSum="11" >

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="15dp"
            android:layout_weight="2"
            android:text="Name" />

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_weight="2"
            android:text="Site Name" />

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_weight="1.5"
            android:text="Plot No" />

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_weight="2.3"
            android:text="Booking Id" />

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_weight="1.6"
            android:text="Booking Date" />

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_weight="1.6"
            android:text="Cancel Date" />
    </LinearLayout>
</HorizontalScrollView>

android:layout\u width=“match\u parent”它也提供了相同的视图,没有任何更改。我尝试在代码中实现您的布局,发现您需要使用自定义行元素。您将附加行布局而不是字符串。这可以帮助您:
listView = (ListView) findViewById(R.id.cancel_booking_listView);

     final View headerView = getLayoutInflater().inflate(R.layout.rowlist_header,
             listView , false);
     listView .addHeaderView(headerView);