如何将listview放入horizo​​ntalscrollview中,以便列表可以水平滚动?

时间:2018-12-17 06:25:20

标签: java android android-listview horizontal-scrolling horizontalscrollview

我正在创建一个应用程序,其需求就像我有一个可以垂直滚动的列表,并且在该列表内,每个项目都有一个必须水平滚动的列表。所以我必须在水平滚动视图中设置该列表。我已经为该数据创建了一个自定义adpater,该数据在列表中显示一切正常,但是只有一个问题是列表垂直滚动,因为我无法将列表水平设置。请帮助我搜索了很多答案,但是没有用。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:padding="5dp">

        <android.support.v7.widget.CardView
            android:id="@+id/card_view_applicant"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="3dp"
            android:background="#fff"
            app:cardCornerRadius="8dp"
            app:cardElevation="1dp">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:orientation="horizontal">

                <TextView
                    android:id="@+id/tv_table_no"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:padding="8dp"
                    android:text="T1"
                    android:textAlignment="center"
                    android:textColor=" #00008B"
                    android:textSize="25sp"
                    android:textStyle="bold" />

                <View
                    android:layout_width="1dp"
                    android:layout_height="match_parent"
                    android:background="#000000" />

            </LinearLayout>

            <HorizontalScrollView
                android:id="@+id/hsv"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:fillViewport="true"
                android:measureAllChildren="false"
                android:scrollbars="none">

                <RelativeLayout
                    android:layout_width="wrap_content"
                    android:layout_marginLeft="50dp"
                    android:layout_height="match_parent">

                    <ListView
                        android:id="@+id/lv_timing"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_alignParentRight="true"/>

                </RelativeLayout>

            </HorizontalScrollView>

        </android.support.v7.widget.CardView>

    </RelativeLayout>

</LinearLayout>

我试图做这样的事情,但这是行不通的,并且我不想使用任何recyclerview,我的要求很简单,我只想显示出这就是为什么。

2 个答案:

答案 0 :(得分:1)

您必须使用RecyclerView进行水平滚动,例如:

// These are important and needed before anything else
import 'zone.js/dist/zone-node';
import 'reflect-metadata';

import { enableProdMode } from '@angular/core';

import * as express from 'express';
import { join } from 'path';

// Faster server renders w/ Prod mode (dev mode never needed)
enableProdMode();

// Express server
const app = express();

const PORT = process.env.PORT || 4000;
const DIST_FOLDER = join(process.cwd(), 'dist');

// * NOTE :: leave this as require() since this file is built Dynamically from webpack
const { AppServerModuleNgFactory, LAZY_MODULE_MAP } = require('./dist/server/main');

// Express Engine
import { ngExpressEngine } from '@nguniversal/express-engine';
// Import module map for lazy loading
import { provideModuleMap } from '@nguniversal/module-map-ngfactory-loader';

app.engine('html', ngExpressEngine({
  bootstrap: AppServerModuleNgFactory,
  providers: [
    provideModuleMap(LAZY_MODULE_MAP)
  ]
}));

app.set('view engine', 'html');
app.set('views', join(DIST_FOLDER, 'browser'));

// TODO: implement data requests securely
app.get('/api/*', (req, res) => {
  res.status(404).send('data requests are not supported');
});

// Server static files from /browser
app.get('*.*', express.static(join(DIST_FOLDER, 'browser')));

// All regular routes use the Universal engine
app.get('*', (req, res) => {
  res.render('index', { req });
});

// Start up the Node server
app.listen(PORT, () => {
  console.log(`Node server listening on http://localhost:${PORT}`);
});

答案 1 :(得分:0)

android:layout_weight="1"中使用ListView。将LinearLayout设为ListView而不是RelativeLayout的父布局,然后检查其是否有效。我认为应该可以。

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