我希望当我的活动加载时,scrollview的顶部将是屏幕高度的一半(如img_1.png)。但我得到它的底部(如img_2.png)。并且在滚动期间它必须可上下滚动(如img_3.png,img_4.png,img_5.png在驱动器链接中)。
这是我的代码。
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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:orientation="vertical"
tools:context=".Main4Activity">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:theme="@style/AppTheme.AppBarOverlay"
app:elevation="6dp">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/col_toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:contentScrim="?android:attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlwaysCollapsed">
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:scrollIndicators="bottom"
android:background="@android:color/black"
app:layout_collapseMode="parallax"/>
<android.support.design.widget.TabLayout
android:id="@+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabBackground="@drawable/tab_selector"
app:tabGravity="center"
android:layout_gravity="bottom"
app:tabIndicatorHeight="0dp"/>
</android.support.design.widget.CollapsingToolbarLayout>
<View
android:id="@+id/view_below_image"
android:layout_width="match_parent"
android:layout_height="5dp"
android:background="@color/colorPrimary"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:id="@+id/nested_scroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:id="@+id/layout_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TEST"
android:textSize="20dp"
android:textStyle="bold" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="About me"
android:textSize="15dp" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="5dp"
android:background="@color/colorPrimary" />
<TextView
android:layout_width="match_parent"
android:layout_height="650dp"
android:text="Description"
android:textSize="50dp" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
提前感谢您的帮助。
https://drive.google.com/open?id=1hDELP83a3YV1p1GxnfG0IpLmfwQFKWfr
跟我一样的问题。
我只想将AppBarLayout高度设为MATCH_PARENT。但是当我第一次打开活动时,我需要它在屏幕的一半底部。在滚动之后,AppBarLayout将像@Abhinav上传的IMAGE 3,4,5一样扩展。
你有定义
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:theme="@style/AppTheme.AppBarOverlay"
app:elevation="6dp">
而不是给出一些静态值,所以你会得到你的结果
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar_layout"
android:layout_width="match_parent"
android:layout_height="200dp"
android:theme="@style/AppTheme.AppBarOverlay"
app:elevation="6dp">