我能够以某种方式使用RecyclerView。在我的RecyclerView中为特定项目创建视图时,recyclerview项目布局与父项匹配。是否有可能使ScrollView匹配尺寸的第一个视图屏幕?
我想知道这是否也可以使用ScrollView?
这里就是我所做的迄今:
滚动型的xml:
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/scrollview_homescreen"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<LinearLayout
android:id="@+id/linearlayout_homescreen"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="@layout/listitem_comic_menu"/>
<LinearLayout
android:id="@+id/linearlayout_comic_listings"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
</LinearLayout>
</LinearLayout>
</ScrollView>
内容:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/relativelayout_homescreen"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/imageview_menu_bg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:adjustViewBounds="true" />
<ImageView
android:id="@+id/imageview_menu_title_bg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/starwars_webtoon_home_1_logo"
android:scaleType="fitXY"
android:adjustViewBounds="true" />
<Button
android:id="@+id/button_start_reading"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_above="@+id/button_menu"
android:layout_marginBottom="18dp"
android:text="@string/button_start_reading"
android:gravity="start"
android:drawableRight="@drawable/ic_keyboard_arrow_right_black_24dp"
android:drawableEnd="@drawable/ic_keyboard_arrow_right_black_24dp"
android:background="@drawable/button_bg"
android:textSize="18sp"
android:layout_marginStart="12dp"
android:layout_marginLeft="12dp"
android:layout_marginEnd="12dp"
android:layout_marginRight="12dp" />
<Button
android:id="@id/button_menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
android:layout_marginBottom="28dp"
android:text="@string/button_menu"
android:textSize="18sp"
android:textColor="#FFFFFF"
android:drawableLeft="@drawable/ic_menu_white_24dp"
android:drawableStart="@drawable/ic_menu_white_24dp"
android:background="?android:attr/selectableItemBackground" />
</RelativeLayout>
那么我想干什么?基本上这是为漫画上市。第一项应该是主屏幕,几个按钮,以及整个应用程序徽标。下一个项目应该显示列表(我有40项相同的宽度和高度)和一个页脚。
我需要我的主屏幕以匹配父屏幕。所以当我滚动最上面的部分时,第一个项目(第一个视图,它是主屏幕)填充整个设备屏幕。
我能够在RecyclerView上做到这一点,看起来不错。我遇到了一些困扰我的问题,我必须广泛地解决这个问题,我正在通过该系统进行黑客攻击,并且我意识到RecyclerView并不是真正适合这种情况的最佳布局。我目前正在决定是否切换到ScrollView并动态/静态添加漫画项目。但是,主屏幕是第一个视图与屏幕设备不匹配。
我只想问,这是否可能在ScrollView中完成?
谢谢!
你应该使用 “万有引力” 属性 –
@Saret,你可以请提供一个例子吗?我仍然在努力了解重力如何在这里提供帮助,而事实上我正在寻求维度。 –
对不起,我的意思是“重量”而不是重力。你可以在listitem_comic_menu的相对布局中添加android:weight =“1”。 –