gpt4 book ai didi

android - RecyclerView match_parent 中带有 horizo​​ntalScrollview 的自定义 View 不起作用

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

enter image description here我有一个包含我的自定义 View 的 RecyclerView。我的自定义 View 无法获得所有宽度,所以我将其配置为 match_parent.我想要的是水平 ScrollView 将占据所有屏幕,并且卡片将占据屏幕宽度(因此黄色部分将在开始时留在外面)

我试过使用 LayoutInflater.from(getContext()).inflate(R.layout.view_home_screen_card, (ViewGroup) this, false), 但没用

我也尝试过以编程方式设置宽度,但在它发生变化之前的几毫秒内我看到了错误的尺寸,而且它看起来很难看。

奇怪的是,当我取出水平 ScrollView 时, View 占据了所有位置。

附上布局

 <?xml version="1.0" encoding="utf-8"?> <merge
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/horizontal_scroll_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:scrollbars="none">

<LinearLayout
android:id="@+id/view_home_card_and_button_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">


<ImageView
android:layout_width="100dp"
android:layout_height="150dp"
android:background="@color/amber_200" />

<android.support.v7.widget.CardView
android:id="@+id/cardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/half_unit"
app:cardCornerRadius="@dimen/8dp">


</android.support.v7.widget.CardView>


</LinearLayout>

</HorizontalScrollView>


</merge>

还有什么想法吗?

最佳答案

你的 recyclerview 有 match_parent 宽度吗?如果没有,那就去做吧。

关于android - RecyclerView match_parent 中带有 horizo​​ntalScrollview 的自定义 View 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53740655/

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