内容下推
问题描述:
我有一个屏幕包含可折叠工具栏(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被推出屏幕。
有什么我做错了吗?任何建议都会有帮助! 谢谢大家,
答
试试这种方式我希望它有帮助。
<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和重力将中心,使线性布局的所有子将在所述线性布局的中心。线性布局也出现在相对布局的中心。