我试着在教程中搜索ScrollView inside ScrollView,我找到了很多,但没有一个适合我。这是我的布局。第二个ScrollView (id = scroll_view_carousel)不起作用。请帮帮我。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:fitsSystemWindows="true"
android:orientation="vertical"
tools:context="com.rytmus.app.activities.DetailsActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/white"
android:theme="@style/Toolbar"
app:collapseIcon="@drawable/ic_arrow_back_white_24dp"
app:layout_scrollFlags="scroll|enterAlways"
app:title="Rytmus"
app:titleTextColor="@color/colorPrimary">
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<ScrollView
android:id="@+id/scroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="0dp">
<ImageView
android:id="@+id/big_logo"
android:layout_width="match_parent"
android:layout_height="160dp"
android:scaleType="centerCrop" />
<ScrollView
android:id="@+id/scroll_view_carousel"
android:layout_width="match_parent"
android:layout_height="75dp"
android:layout_below="@id/big_logo"
android:background="@color/colorBlack">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_marginTop="5dp"
android:orientation="horizontal">
<ImageView
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginRight="5dp"
android:scaleType="centerCrop"
android:src="@drawable/background_rytmus_disco" />
<ImageView
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginRight="5dp"
android:scaleType="centerCrop"
android:src="@drawable/background_rytmus_disco" />
<ImageView
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginRight="5dp"
android:scaleType="centerCrop"
android:src="@drawable/ic_arrow_back_white_24dp" />
<ImageView
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginRight="5dp"
android:scaleType="centerCrop"
android:src="@drawable/background_rytmus_disco" />
<ImageView
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginRight="5dp"
android:scaleType="centerCrop"
android:src="@drawable/com_facebook_button_like_background" />
<ImageView
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginRight="5dp"
android:scaleType="centerCrop"
android:src="@drawable/background_rytmus_disco" />
<ImageView
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginRight="5dp"
android:scaleType="centerCrop"
android:src="@drawable/background_rytmus_disco" />
<ImageView
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginRight="5dp"
android:scaleType="centerCrop"
android:src="@drawable/background_rytmus_disco" />
<ImageView
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginRight="5dp"
android:scaleType="centerCrop"
android:src="@drawable/background_rytmus_disco" />
<ImageView
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginRight="5dp"
android:scaleType="centerCrop"
android:src="@drawable/background_rytmus_disco" />
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="@+id/four_buttons"
android:layout_width="match_parent"
android:layout_height="46dp"
android:layout_below="@id/scroll_view_carousel"
android:background="@color/colorAccent"
android:orientation="horizontal">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tabFirstsButtonsLinearLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:orientation="vertical">
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="100dp"
android:layout_height="fill_parent"
android:orientation="vertical" />
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tabSecondsButtonsLinearLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerHorizontal="true"
android:layout_weight="1"
android:orientation="vertical">
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
</LinearLayout>
<LinearLayout
android:id="@+id/tabs_disco_details"
android:layout_width="match_parent"
android:layout_height="46dp"
android:layout_below="@id/four_buttons"
android:background="@color/colorPrimary"
android:orientation="horizontal">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tabDescriptionLinearLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:orientation="vertical">
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tabDescription"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_margin="4dp"
android:gravity="center"
android:paddingLeft="10dp"
android:text="Descripción"
android:textColor="@color/white"
android:textSize="13sp" />
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="90dp"
android:layout_height="fill_parent"
android:orientation="vertical" />
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tabValorationLinearLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerHorizontal="true"
android:layout_weight="1"
android:orientation="vertical">
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tabValoration"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_margin="4dp"
android:gravity="center"
android:paddingLeft="10dp"
android:text="Valoraciones"
android:textColor="@color/white"
android:textSize="13sp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/container_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/tabs_disco_details"
android:orientation="vertical" />
<LinearLayout
android:layout_width="101dp"
android:layout_height="101dp"
android:layout_below="@id/scroll_view_carousel"
android:layout_centerHorizontal="true"
android:background="@drawable/border"
android:translationY="-5dp">
<ImageView
android:id="@+id/imagen_logo"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_centerHorizontal="true"
android:src="@drawable/background_rytmus_disco" />
</LinearLayout>
</RelativeLayout>
</ScrollView>
</LinearLayout>解决方案
我将第二个ScrollView更改为一个HorizontalScrollView,现在可以工作了!
发布于 2016-08-08 23:08:50
非常糟糕的编程实践。您不能在scrollView中嵌入scrollView。
一般来说,scrollView中的ListView也不能工作,因为ListView有自己的滚动功能,我们再次将它嵌入到scrollView类中,这就是为什么它会产生jerk。
同样,您应该如何在scrollView中集成scrollView?从逻辑上思考它应该是如何实现的?它会混淆哪个scrollView会被触发?
发布于 2016-08-09 02:19:41
我认为你应该使用嵌套的RecyclerViews。如果你四处搜索,你会发现有很多例子。我在这里做了一个简单的https://github.com/ozv101/NestedRecycler
发布于 2016-08-09 02:07:15
阅读关于ScrollView的文章。
ScrollView是一种特殊的布局,旨在容纳比实际大小更大的视图。当视图大小超过ScrollView大小时,它会自动添加滚动条,并且可以垂直滚动。ScrollView只能包含一个直接子级。这意味着,如果你有一个包含更多视图控件的复杂布局,你必须将它们包含在另一个标准布局中,比如LinearLayout、TableLayout或RelativeLayout。您可以指定layout_height和layout_width来调整屏幕的高度和宽度。
Scrollview对于需要滚动的屏幕是理想的,但当使用Scrollview呈现更大的数据列表时,它是一种开销。安卓提供了专门的适配器视图,如ListView、GridView和RecyclerView (在安卓棒棒糖中引入)。
永远不要将ScrollView与ListView或GridView一起使用,因为它们都会处理自己的垂直滚动。ScrollView仅支持垂直滚动。HorizontalScrollView用于水平滚动。
android:fillViewport属性定义ScrollView是否应拉伸其内容以填充视口。您可以通过从java类调用setFillViewport(boolean)方法来设置相同的属性。
不要在scrollview...may中使用scrollview,上面的文档对你有帮助!
https://stackoverflow.com/questions/38832664
复制相似问题