NestedScrollview中的内容被下推

时间:2017-06-14 11:06:49

标签: android nestedscrollview

我的屏幕包含可折叠工具栏(AppBarLayout)和带有NestedScrollviews的可滚动内容

我的主要布局:

<android.support.design.widget.CoordinatorLayout
    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="match_parent">

<android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:theme="@style/ToolbarTheme"
        android:layout_width="match_parent"
        android:layout_height="@dimen/actionBarHeight"
        android:background="@color/colorPrimary"
        app:layout_scrollFlags="scroll|enterAlways"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

    </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="match_parent"
        android:fillViewport="true"
        android:scrollbars="none"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">
    <FrameLayout
        android:id="@+id/layoutMainContent"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
    </android.support.v4.widget.NestedScrollView>

    </android.support.design.widget.CoordinatorLayout>

我在FrameLayout layoutMainContent中放置的布局内容如下所示

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
android:background="@color/colorBackground">

<LinearLayout
    android:id="@+id/layoutAbout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:layout_centerInParent="true">
    <ImageView
        android:id="@+id/ivLogo"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_gravity="center_horizontal"
        android:src="@drawable/logo"/>
</LinearLayout>

<TextView
    android:id="@+id/tvViewDetail"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:textColor="@color/colorPrimary"
    android:text="@string/see_license"
    android:gravity="center_horizontal"/>
</RelativeLayout>

我想要的是徽标图像位于中心,TextView(tvViewDetail)位于屏幕的底部。但是,徽标图像不在中心(向下推一点),并且tvViewDetail被推出屏幕。

我做错了什么吗?任何建议都会有所帮助! 谢谢大家,

1 个答案:

答案 0 :(得分:0)

尝试这种方式我希望它有所帮助。

<RelativeLayout
         xmlns:android="http://schemas.android.com/apk/res/android"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         android:background="@color/colorBackground">

         <LinearLayout
                android:id="@+id/layoutAbout"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:gravity="center"
                android:layout_centerInParent="true">
                    <ImageView
                         android:id="@+id/ivLogo"
                         android:layout_width="100dp"
                         android:layout_height="100dp"
                         android:src="@drawable/logo"/>

                    <TextView
                        android:id="@+id/tvViewDetail"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:textColor="@color/colorPrimary"
                        android:text="@string/see_license"/>
                 </LinearLayout>


              </RelativeLayout>

因此,linearlayout的高度和宽度将为wrap_content,而gravity将为center,因此该线性布局的所有子项都将位于线性布局的中心。线性布局也出现在相对布局的中心。

相关问题