gpt4 book ai didi

android - recyclerview 项目中出现意外空间

转载 作者:行者123 更新时间:2023-11-29 14:30:28 25 4
gpt4 key购买 nike

这是个愚蠢的问题,但我找不到我做错了什么。

我正在使用 FirebaseRecyclerAdapter 来填充 recyclerView,但项目中出现了意想不到的空间。 enter image description here

fragment 类:

    @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_tags, container, false);

mProgressBar = (ProgressBar)view.findViewById(R.id.progressBar);
mTagsRecyclerView = (RecyclerView) view.findViewById(R.id.tagsRecyclerView);
mLinearLayoutManager = new LinearLayoutManager(getContext());

mFirebaseDatabaseReference = FirebaseDatabase.getInstance().getReference();
mFirebaseAdapter = new FirebaseRecyclerAdapter<Tags, TagsViewHolder>(
Tags.class,
R.layout.item_message,
TagsViewHolder.class,
mFirebaseDatabaseReference.child("tags")) {

@Override
protected void populateViewHolder(TagsViewHolder viewHolder, Tags tags, int position) {
mProgressBar.setVisibility(ProgressBar.INVISIBLE);
viewHolder.tagTextView.setText(tags.getTagname());
viewHolder.usrTextView.setText(tags.getUserid());
}
};


mFirebaseAdapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() {
@Override
public void onItemRangeInserted(int positionStart, int itemCount) {
super.onItemRangeInserted(positionStart, itemCount);
}
});

mTagsRecyclerView.setLayoutManager(mLinearLayoutManager);
mTagsRecyclerView.setAdapter(mFirebaseAdapter);

mTagsRecyclerView.addOnItemTouchListener(new RecyclerViewItemClickListener(getContext(),
new RecyclerViewItemClickListener.OnItemClickListener() {
@Override public void onItemClick(View v, int position) {
//TODO:
// do something on item click
Log.d("Item clicked at",Integer.toString(position));
}
}));
return view;
}

fragment 布局:

<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.helpplusapp.amit.helpplus.TagsFragment">

<android.support.v7.widget.RecyclerView
android:id="@+id/tagsRecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<ProgressBar
style="?android:attr/progressBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/progressBar"
android:layout_gravity="center"
/>

列表项布局:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="@drawable/view_separator"
android:paddingTop="@dimen/margin_default"
android:paddingBottom="@dimen/margin_default"
android:showDividers="end">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="@+id/tagTextView"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="@+id/usrTextView"
/>

</LinearLayout>

请提出建议。

最佳答案

在listitemlayout xml文件中设置线性布局的高度来包裹内容

关于android - recyclerview 项目中出现意外空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38807095/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com