【发布时间】:2018-12-12 10:11:11
【问题描述】:
我有一个包含我的自定义视图的RecyclerView。
我的自定义视图没有得到所有宽度,所以我将其配置为match_parent.
我想要的是水平滚动视图将占据所有屏幕,并且卡片将占据屏幕宽度(因此黄色部分将在开始时留在外面)
我尝试使用LayoutInflater.from(getContext()).inflate(R.layout.view_home_screen_card, (ViewGroup) this, false),,但没有成功
我还尝试以编程方式设置宽度,但我在几毫秒内看到了错误的大小,然后它就会改变并且看起来很丑。
奇怪的是,当我取出水平滚动视图时,视图全部到位。
附上布局
<?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>
还有什么想法吗?
【问题讨论】:
-
请分享您的自定义布局代码
-
@RahulChokshi 我已经编辑了问题
标签: android layout android-recyclerview