在我的Android应用程序中,我有一个登录屏幕,到目前为止工作正常。它以根ScrollView
结构,其中有一个垂直LinearLayout
名称为rootLayer。在那个rootLayer中,我有四个连续LinearLayout
,你可以在下面的xml布局文件中看到。但我只同时展示了三个。根据登录或注销的情况, 1st (loggedOffLayer)或 2nd (loggedInLayer)图层; AND 然后 3rd 和第四 4th (灰色)总是:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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:fillViewport="true"
android:padding="0dp"
>
<LinearLayout
android:id="@+id/rootLayer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:clickable="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="vertical"
android:padding="0dp"
>
<LinearLayout
android:id="@+id/loggedOffLayer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:visibility="visible">
<!-- one two views and buttons-->
</LinearLayout>
<LinearLayout
android:id="@+id/loggedInLayer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/loggedOffLayer"
android:orientation="vertical"
android:visibility="gone"
tools:visibility="visible">
<!-- some labels, textviews and buttons -->
</LinearLayout>
<LinearLayout
android:id="@+id/about_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/bottomLayer"
android:layout_marginBottom="@dimen/grid1"
android:gravity="center"
android:orientation="horizontal"
tools:visibility="visible">
<!-- labels with about text -->
</LinearLayout>
<LinearLayout
android:id="@+id/bottomLayer"
android:layout_width="match_parent"
android:layout_height="120dp"
android:background="@color/light_background"
android:orientation="vertical">
<!-- imageviews and labels with pictures and legal text-->
</LinearLayout>
</LinearLayout>
</ScrollView>
&#13;
当我登录时,每件事都很好。但是当我注销时,如在之后,在我的最后一层(灰色)之后有一个白色的空白区域(红色箭头)。
如何将最后一层粘贴到底部,以便每种情况下都没有白色条纹?
答案 0 :(得分:0)
试试这段代码:---
<?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:orientation="vertical"
android:layout_weight="2"
android:fillViewport="true"
>
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1.8">
<LinearLayout
android:id="@+id/rootLayer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true"
android:clickable="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="vertical"
android:padding="0dp">
<LinearLayout
android:id="@+id/loggedOffLayer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:visibility="visible">
<!-- one two views and buttons-->
</LinearLayout>
<LinearLayout
android:id="@+id/loggedInLayer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/loggedOffLayer"
android:orientation="vertical"
android:visibility="gone"
tools:visibility="visible">
<!-- some labels, textviews and buttons -->
</LinearLayout>
<LinearLayout
android:id="@+id/about_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/bottomLayer"
android:layout_marginBottom="15dp"
android:gravity="center"
android:orientation="horizontal"
tools:visibility="visible">
<!-- labels with about text -->
</LinearLayout>
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="@+id/bottomLayer"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".2"
android:background="@color/Black"
android:orientation="vertical">
<!-- imageviews and labels with pictures and legal text-->
</LinearLayout>
</LinearLayout>
使用此代码,您的bottomLayer会粘在底部。
答案 1 :(得分:0)
我认为这很难做到因为您使用scroll layout
而scroll layout
会在您添加或删除widgets
时增长和缩小。
此外,它与显示屏有所不同resolutions
。对于低resolution
scroll layout
将增长,并且对于高分辨率scroll layout
将缩小,因为屏幕上有大量空间。