![](/img/trans.png)
[英]What is the best way to put a ListView inside HorizontalScrollView?
[英]how to put listview inside a horizontalscrollview so that list can scroll hoizontally?
我正在创建一个要求像我有一个垂直滚动列表的应用程序,并且在该列表内部,每个项目都有一个必须水平滚动的列表。 所以我必须在水平滚动视图中设置该列表。 我已经为该数据创建了一个自定义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,我的要求很简单,我只想显示一些这就是为什么。
您必须使用RecyclerView进行水平滚动,例如:
LinearLayoutManager layoutManager= new
LinearLayoutManager(this,LinearLayoutManager.HORIZONTAL, false);
mRecyclerView = (RecyclerView) findViewById(R.id.recycler_view);
mRecyclerView.setLayoutManager(layoutManager);
在ListView
使用android:layout_weight="1"
。 将LinearLayout
设为ListView
的父级布局,而不是RelativeLayout
然后检查其是否正常工作。 我认为应该工作。
<LinearLayout
..........>
<ListView
........
android:layout_weight="1"/>
</LinearLayout>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.