我有一个带有垂直滚动的列表视图,其项目包含将水平滚动的RecyclerView。 但是当我水平滚动时,RecyclerView不允许我滚动到列表中的最后一项(下图)。发生了什么事?甚至,我强迫它滚动到最后一项,方法是设置 linearLayoutManager.setStackFromEnd(true); 它仍然不起作用,只滚动到第8项的一半,而不是10列表中的最后一项< / p>
修改:添加代码:
list.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:padding="20dp">
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TableRow>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="@+id/imgExcercisePhoto"
android:layout_width="100dp"
android:layout_height="100dp" />
<TextView android:text="aaa"
android:id="@+id/tvExerciseName"
android:layout_width="100dp"
android:layout_height="wrap_content" />
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/rvExcerciseRecords"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:layout_margin="10dp"
android:paddingRight="50dp"
android:scrollbars="horizontal">
</android.support.v7.widget.RecyclerView>
</TableRow>
</TableLayout>
</LinearLayout>
list_item.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="100dp"
android:layout_height="match_parent"
android:clipToPadding="false"
android:paddingRight="10dp">
<TextView
android:id="@+id/tvTemp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
list_item_horizontal.xml
public View getView(int i, View convertView, ViewGroup viewGroup) {
View view = convertView;
if (convertView == null) {
view = inflater.inflate(R.layout.list_item, null);
viewHolder = new ViewHolder();
viewHolder.title = (TextView) view.findViewById(R.id.tvExerciseName);
view.setTag(viewHolder);
recyclerView = (RecyclerView)view.findViewById(R.id.rvExcerciseRecords);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(activity, LinearLayoutManager.HORIZONTAL, false);
linearLayoutManager.setStackFromEnd(true);
recyclerView.setLayoutManager(linearLayoutManager);
recyclerView.setAdapter(trackingPlanHorizontalAdapter);
recyclerView.setNestedScrollingEnabled(false);
} else {
viewHolder = (ViewHolder) view.getTag();
}
if (data.size() > 0) {
ExerciseModel exercise = (ExerciseModel) data.get(i);
viewHolder.title.setText(exercise.getTitle());
} else {
viewHolder.title.setText("No data");
}
return view;
}
列表适配器代码:
public TrackingPlanHorizontalViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item_horizontal, parent, false);
return new TrackingPlanHorizontalViewHolder(itemView);
}
@Override
public void onBindViewHolder(TrackingPlanHorizontalViewHolder holder, int position) {
holder.textView.setText(horizontalList.get(position));
}
回收适配器代码:
CLLocationManager
答案 0 :(得分:0)
是的,我发现了您的问题,您的 list_item.xml 存在问题,请使用以下代码更改您的列表项,
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="20dp">
<LinearLayout
android:id="@+id/first_panel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:src="@mipmap/ic_launcher"
android:id="@+id/imgExcercisePhoto"
android:layout_width="100dp"
android:layout_height="100dp" />
<TextView
android:id="@+id/tvExerciseName"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="aaa" />
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:layout_toRightOf="@+id/first_panel"
android:id="@+id/rvExcerciseRecords"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</android.support.v7.widget.RecyclerView>
</RelativeLayout>