【发布时间】:2018-11-07 11:23:27
【问题描述】:
如何在 xml 文件中添加具有相对布局、回收器视图、文本视图、图像视图的滚动视图。下面是相应的xml代码:
请通过下面的代码。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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="match_parent"
tools:context=".StoryList">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/skandaimagestory"
android:src="@drawable/pictureskanda"
android:layout_width="match_parent"
android:layout_height="130dp" />
<TextView
android:id="@+id/Heading"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_below="@+id/skandaimagestory"
android:gravity="center"
android:padding="17dp"
android:text="SURVIVORS TALES"
android:textSize="20dp"
android:textStyle="bold" />
<LinearLayout
android:layout_below="@+id/Heading"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.RecyclerView
android:background="#f6facf"
android:padding="10dp"
android:id="@+id/story_list"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
</ScrollView>
提前谢谢你。
【问题讨论】:
-
你能解释一下为什么需要一个 ScrollView 吗?比如你想达到什么目标?如果您需要它的唯一原因是在上方放置一些视图并使其一起滚动,您只需将 CoordinatorLayout 与 AppbarLayout 一起使用。更优雅的方式
-
如果你试图获得一个元素列表,其中第一个是标题,我建议你只保留 RecyclerView 并使用不同的 ViewTypes。无论如何,您不应该使用“wrap_content”作为 ScrollView 和 RecyclerView 的高度。
-
感谢您的帮助..
标签: android android-studio android-layout android-scrollview android-relativelayout