我有一個ScrollView和兩個LinearLayouts的片段。我希望能夠將第一個LinearLayout放在頂部(重力頂部),第二個放在底部。這裏是我的代碼在ScrollView中設置重力
<LinearLayout 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"
android:background="@android:color/white"
tools:context=".activities.NavigationDrawerFragment"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="@color/darkblue"
android:paddingBottom="40dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="20dp"
android:layout_gravity="center|top">
<ImageView
android:id="@+id/img_drawler_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginLeft="5dp">
<TextView
android:id="@+id/txt_drawler_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/txt_drawler_name"
android:textColor="@android:color/white"
android:textStyle="bold"
android:textSize="20sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<TextView
android:id="@+id/txt_drawler_time_avariable"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/txt_drawler_time_avariable"
android:textColor="@android:color/white"
android:textSize="12sp"
android:textIsSelectable="false" />
<TextView
android:id="@+id/txt_drawler_time_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/empty"
android:textSize="12sp"
android:textColor="@android:color/white"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
<ScrollView
android:scrollbars="none"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:id="@+id/id_drawable_scrollView">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="top">
<Button
android:id="@+id/btn_drawler_home"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:gravity="center|left"
android:paddingBottom="10dp"
android:paddingLeft="10dp"
android:paddingTop="10dp"
android:text="@string/btn_drawler_home"
android:textColor="@android:color/black"
android:textSize="16sp" />
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="@color/lightgray" />
<Button
android:id="@+id/btn_drawler_select"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/btn_drawler_class_select"
android:textColor="@android:color/black"
android:background="@android:color/transparent"
android:gravity="center|left"
android:textSize="16sp"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:paddingLeft="10dp" />
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="@color/lightgray"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@color/green"
android:paddingBottom="20dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="30dp"
android:gravity="bottom">
<TextView
android:id="@+id/btn_drawler_toc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:text="@string/btn_drawler_toc"
android:gravity="left|center"
android:textColor="@android:color/white"
android:textSize="16sp"
android:paddingBottom="20dp"
/>
<TextView
android:id="@+id/btn_drawler_faq"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:text="@string/btn_drawler_faq"
android:gravity="left|center"
android:textColor="@android:color/white"
android:textSize="16sp"
android:paddingBottom="20dp"
/>
<TextView
android:id="@+id/btn_drawler_contact"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:text="@string/btn_drawler_contact"
android:gravity="left|center"
android:textColor="@android:color/white"
android:textSize="16sp"
android:paddingBottom="20dp"
/>
<TextView
android:id="@+id/btn_drawler_logout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:text="@string/btn_drawler_logout"
android:gravity="left|center"
android:textColor="@android:color/white"
android:textSize="16sp"
/>
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
似乎ScrollView的孩子不能fill_parent或match_parent。這可能嗎?
我想實現
謝謝
更新1
我不知道爲什麼不利用這種結構的工作,在這最後的情況下滾動什麼不工作。
<RelativeLayout>
<ScrollView>
<LinearLayout>
<LinearLayout>
</LinearLayoyt>
<LinearLayout>
</LinearLayoyt>
</LinearLayoyt>
</ScrollView>
<LinearLayout>
</LinearLayoyt>
</RelativeLayout>
順便說一句,我覺得這對我的工作(使用不同的XML佈局)的設置,但我不知道爲什麼不工作,也許有人能幫助我理解。
放圖像的頂部
LinearLayout
android:layout_alignParentBottom="true"
,我不明白你想要什麼,什麼是目前的狀況 –這個問題讓沒有意義。 「ScrollView」可能具有無限高度,具體取決於其包含的視圖數量(及其組合高度)。 「ScrollView」的「頂部」或「底部」的概念只有在創建並填充了各種視圖後纔有效。將一些東西放在ScrollView的「頂部」和其他位於「底部」的東西(大概在中間存在某種空隙)並不是ScrollView的工作原理。 – Squonk
謝謝@Squonk。你幫助我理解了發生的更好,但是我的問題是如果ScrollView中的元素小於「我有的高度」ScrollView在底部填充了白色背景,我更喜歡中間的填充,在作爲ScrollView子項的LinearLayout子項的兩個LinearLayout之間。 – agusgambina