gpt4 book ai didi

android - RECYCLERVIEW 空间在 Android 应用程序的项目之间

转载 作者:行者123 更新时间:2023-11-30 00:53:46 25 4
gpt4 key购买 nike

我有一个正在开发的项目,但我遇到了一个问题,我的 android 应用程序中的两个项目之间出现了很大的差距,我曾尝试查看这里以前关于如何解决问题的所有建议,但没有一个为我工作

这是导致问题的布局

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:layout_height="match_parent"
android:orientation="horizontal">

<android.support.v7.widget.RecyclerView
android:id="@+id/prodct_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="false"
android:scaleType="fitXY"
android:padding="0dp"
android:adjustViewBounds="true"/>

<android.support.design.widget.FloatingActionButton
android:id="@+id/actionbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_gravity="end"
android:visibility="gone" />

这是我在与上述布局相关联的 Activity 上的 oncreate 方法:

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

tabletSize = getResources().getBoolean(R.bool.isTablet);
if (!tabletSize) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
setContentView(R.layout.order_details);

ab = getSupportActionBar();
ab.setDisplayUseLogoEnabled(true);
ab.setDisplayHomeAsUpEnabled(true);

actionButton = (FloatingActionButton) findViewById(R.id.actionbutton);
actionButton.setBackgroundColor(getResources().getColor(R.color.actionbar));
actionButton.setImageResource(R.drawable.ic_action_send);

appPreference = new AppPreference(this);
mRecyclerView = (RecyclerView) findViewById(R.id.prodct_list);
mRecyclerView.setHasFixedSize(true);
mRecyclerView.setItemAnimator(new DefaultItemAnimator());

mLayoutManager = new LinearLayoutManager(this);
mRecyclerView.setLayoutManager(mLayoutManager);

final Intent intent = getIntent();
pyid = intent.getExtras().getLong(Quotes.ID);

mItemsDetail = QuoteItems.getItemsArray(this ,pyid);

mAdapter = new DeliveryDetailsAdapter(this, mItemsDetail);
mRecyclerView.setAdapter(mAdapter);

pContent = new ParseContent(this);
title = intent.getExtras().getString(Quotes.REFERENCE);
if (pyid == 0)
finish();

if (Validating.areSet(title))
ab.setTitle("Quote Details");
else
ab.setTitle(getString(R.string.strorder));

mRecyclerView.addOnItemTouchListener(
new RecylerItemClick(this, new RecylerItemClick.OnItemClickListener() {
@Override
public void onItemClick(View view, int position) {

}
})
);

这是我在 recyclerview 上填充的项目列表:

<android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view11"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/rltotals"
android:layout_below="@+id/autotxtsaleclientname"
card_view:cardBackgroundColor="@color/white"
card_view:cardCornerRadius="7.0dip"
card_view:cardElevation="0dp">

<android.support.v7.widget.RecyclerView
android:id="@+id/prodct_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:scrollbars="vertical" />
</android.support.v7.widget.CardView>

当我在那个部分运行应用程序时,recyclerview 上的项目显示每个项目之间有很大的差距谁能帮我解决元素之间的差距问题

最佳答案

问题出在您的适配器类上。您需要将适配器类的父级高度设置为 wrap_content。由于您的 recylerview 是垂直的,因此您需要将适配器父布局的高度更改为 wrap_content。之后,如果问题存在,检查是否有任何其他适配器 subview 高度是 match_parent,如果是,则将其更改为 wrap_content

希望这对您有帮助:)

关于android - RECYCLERVIEW 空间在 Android 应用程序的项目之间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40521577/

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