嘿我想完全滚动屏幕。我所做的是我在我的活动中使用了一些视图分页器和其他视图的可扩展列表视图。可展开的列表视图在其分配的空间中完美滚动,但我想要的是我的整个活动的布局应该从上到下滚动,这是我的xml代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context="websters.smartindiaserviceapp.Activities.CategoryDetails1">
<include
android:id="@id/tool"
layout="@layout/toolbar"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<android.support.design.widget.AppBarLayout
android:id="@+id/materialup.appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="56dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/main.collapsing"
android:layout_width="match_parent"
android:layout_height="200dp"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
app:layout_scrollFlags="scroll|snap">
<android.support.v4.view.ViewPager
android:id="@+id/vpBanners"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<com.viewpagerindicator.CirclePageIndicator
android:id="@+id/ciBanners"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal"
android:layout_marginBottom="10dp"
android:padding="1dip"
app:fillColor="#ffffff"
app:pageColor="#80cccccc" />
</android.support.design.widget.CollapsingToolbarLayout>
<LinearLayout
android:id="@+id/lldesc"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#ffffff"
android:gravity="left"
android:orientation="vertical"
android:padding="12dp"
android:layout_below="@+id/main.collapsing"
app:layout_scrollFlags="scroll|enterAlways|snap">
<TextView
android:id="@+id/tvdesc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:layout_marginTop="4dp"
android:text="First Line"
android:textAppearance="@style/TextAppearance.AppCompat.Widget.ActionBar.Subtitle"
android:textColor="@android:color/black" />
</LinearLayout>
<LinearLayout
android:id="@+id/llservices"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/selecteditem"
android:gravity="center"
android:orientation="vertical"
android:padding="12dp"
android:layout_below="@+id/lldesc"
app:layout_scrollFlags="scroll|enterAlways|snap">
<TextView
android:id="@+id/tvservices"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:layout_marginTop="4dp"
android:text="Services"
android:textStyle="bold"
android:textSize="20dp"
android:textAppearance="@style/TextAppearance.AppCompat.Widget.ActionBar.Subtitle"
android:textColor="@android:color/white" />
</LinearLayout>
</android.support.design.widget.AppBarLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/frstll"
android:layout_below="@+id/materialup.appbar"
android:orientation="vertical">
<ExpandableListView
android:id="@+id/expandableListView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#ffffff"
android:childDivider="#f4f4f4"
android:dividerHeight="1dp"
android:groupIndicator="@null" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="end"
android:orientation="horizontal">
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right|end"
android:layout_margin="@dimen/activity_horizontal_margin"
android:clickable="true"
android:elevation="8dp"
android:src="@android:drawable/ic_menu_help"
app:backgroundTint="#1abc9c" />
</LinearLayout>
</RelativeLayout>
So help to acheive proper scrolling in this layout file,,
这是我从这个xml代码中获得的布局截图。 建议我必须改变以实现适当的滚动。我应该使用滚动视图或坐标布局以及如何使用?帮帮我们。我需要在此活动的布局中顺利滚动。
答案 0 :(得分:0)
有很多方法,但简单的方法是 - 在列表本身上使用页眉视图或/和页脚视图。 基本上,将所有内容放在ExpendableListView上面,将其作为布局放入另一个.xml文件中,然后在代码中对其进行充气并将其作为标题视图添加到列表中。
即
View header = getLayoutInflater().inflate(R.layout.header, null);
View footer = getLayoutInflater().inflate(R.layout.footer, null);
expandableListView.addHeaderView(header);
expandableListView.addFooterView(footer);
还有另一种方式使用Scroll视图并使expandableListView滚动禁用。您可以找到Here
这里有CoderzPassion的精彩教程。您会发现它更容易。
答案 1 :(得分:0)
试试这个:
<?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="websters.smartindiaserviceapp.Activities.CategoryDetails1">
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:id="@+id/materialup.appbar"
android:layout_width="match_parent"
android:layout_height="200dp"
android:fitsSystemWindows="true"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/main.collapsing"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
app:layout_scrollFlags="scroll|snap">
<include
android:id="@id/tool"
layout="@layout/toolbar"
android:layout_width="fill_parent"
android:layout_height="?attr/actionBarSize" />
<android.support.v4.view.ViewPager
android:id="@+id/vpBanners"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<com.viewpagerindicator.CirclePageIndicator
android:id="@+id/ciBanners"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal"
android:layout_marginBottom="10dp"
android:padding="1dip"
app:fillColor="#ffffff"
app:pageColor="#80cccccc" />
<LinearLayout
android:id="@+id/lldesc"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/main.collapsing"
android:background="#ffffff"
android:gravity="left"
android:orientation="vertical"
android:padding="12dp"
app:layout_scrollFlags="scroll|enterAlways|snap">
<TextView
android:id="@+id/tvdesc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:layout_marginTop="4dp"
android:text="First Line"
android:textAppearance="@style/TextAppearance.AppCompat.Widget.ActionBar.Subtitle"
android:textColor="@android:color/black" />
?
</LinearLayout>
<LinearLayout
android:id="@+id/llservices"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/lldesc"
android:background="@color/selecteditem"
android:gravity="center"
android:orientation="vertical"
android:padding="12dp"
app:layout_scrollFlags="scroll|enterAlways|snap">
<TextView
android:id="@+id/tvservices"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:layout_marginTop="4dp"
android:text="Services"
android:textAppearance="@style/TextAppearance.AppCompat.Widget.ActionBar.Subtitle"
android:textColor="@android:color/white"
android:textSize="20dp"
android:textStyle="bold" />
</LinearLayout>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/activity_horizontal_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:id="@+id/frstll"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/materialup.appbar"
android:orientation="vertical">
<ExpandableListView
android:id="@+id/expandableListView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#ffffff"
android:childDivider="#f4f4f4"
android:dividerHeight="1dp"
android:groupIndicator="@null" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="end"
android:orientation="horizontal">
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right|end"
android:layout_margin="@dimen/activity_horizontal_margin"
android:clickable="true"
android:elevation="8dp"
android:src="@android:drawable/ic_menu_help"
app:backgroundTint="#1abc9c" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
</RelativeLayout>