我将通过适配器填充视图,当iam将数据填充到RV时,无法滚动。
这是我的RC:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/trip_ticket_refresh"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/trip_ticket_recycler"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</android.support.v4.widget.SwipeRefreshLayout>
这个观点填写了RC:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/TripMyTicketScrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:orientation="vertical">
<Button
android:id="@+id/my_ticket_port_and_directions"
android:layout_width="match_parent"
android:layout_height="@dimen/grid_14"
android:layout_marginEnd="@dimen/grid_2"
android:layout_marginLeft="@dimen/grid_2"
android:layout_marginRight="@dimen/grid_2"
android:layout_marginStart="@dimen/grid_2"
android:layout_marginTop="@dimen/grid_1"
android:height="@dimen/grid_5"
android:background="@color/bg_on_board_button"
android:drawableEnd="@drawable/ic_keyboard_arrow_right"
android:drawableLeft="@drawable/ic_rudder_black_32dp"
android:drawablePadding="6dp"
android:drawableRight="@drawable/ic_keyboard_arrow_right"
android:drawableStart="@drawable/ic_rudder_black_32dp"
android:gravity="center|start"
android:padding="@dimen/grid_2"
android:text="@string/my_ticket_port_and_direction"
android:textColor="@color/text_color_my_trip_button"
android:textStyle="bold" />
<include layout="@layout/view_my_trip_time_schedule" />
<include layout="@layout/view_my_trip_passengers_and_cabins" />
<include layout="@layout/view_my_trip_booking_number" />
</LinearLayout>
在<include layout=...
当在屏幕尺寸上查看时,通常会开始滚动,但在这种情况下不会。 适配器现在是空的,因为我必须解决这个问题,我会继续。
你能帮帮我吗? 谢谢。更新 这是Fragment中的RC init
private void initRecyclerView(){
mAdapter = new MyTicketAdapter(getContext());
RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getActivity());
mRecyclerRv.setLayoutManager(mLayoutManager);
mRecyclerRv.setAdapter(mAdapter);
}
适配器暂时不填充任何数据。这是适配器:
public class MyTicketAdapter extends RecyclerView.Adapter<MyTicketAdapter.MyViewHolder> {
private static final int BARCODE_IMAGE_WIDTH = 150;
private static final int BARCODE_IMAGE_HEIGHT = 40;
private Departure mDeparture;
private final Context mContext;
public class MyViewHolder extends RecyclerView.ViewHolder {
//
// @BindView(R.id.my_ticket_booking_number_barcode_ticket)
// ImageView mBarcodeImageView;
//
// @BindView(R.id.my_ticket_booking_number_barcode_booking_number)
// TextView mBookingNumberBelowBarcode;
//
public MyViewHolder(View view) {
super(view);
ButterKnife.bind(this, view);
}
}
/**
* Creates a new instance of this class.
*
* @param context need values from resource.
*/
public MyTicketAdapter(Context context) {
mContext = context;
}
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.list_item_trip_ticket, parent, false);
return new MyViewHolder(itemView);
}
@Override
public void onBindViewHolder(MyTicketAdapter.MyViewHolder holder, int position) {
if (mDeparture == null) {
return;
}
TravelMateLogs.MY_TICKET_ADAPTER.i("--------Departure: " + mDeparture.toString());
// generateBarcode(holder);
}
@Override
public int getItemCount() {
// There is only one item.
if(mDeparture == null){
return 0;
}else {
return 1;
}
}
/**
* Sets the data to be displayed in the list.
*
* @param departure The departure to be displayed in the view. Null will clear the list.
*/
void setData(@Nullable Departure departure) {
mDeparture = departure;
notifyDataSetChanged();
}
}
答案 0 :(得分:0)
--service-node-port-range
如果是换行,则不能看到recyclerview。另请发布recyclerview初始化。
答案 1 :(得分:0)
解决方案:
我必须将所有部分包装到linearlayout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/TripMyTicketScrollView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/bg_trip_tab_view"
android:orientation="vertical"
android:paddingBottom="@dimen/grid_14">
<include layout="@layout/view_my_trip_time_schedule" />
<include layout="@layout/view_my_trip_passengers_and_cabins" />
<include layout="@layout/view_my_trip_booking_number" />
</LinearLayout>
</LinearLayout>
现在是工作......