我已經嘗試了幾種方法來使其工作,但迄今爲止沒有成功。 需要使用主滾動視圖來啓用片段之間的滾動。 RelativeLayout就在那裏,所以我們對齊所有片段父屏幕底部的「Back/Save/Done」按鈕。如何在可滾動的RelativeLayout內啓用LinearLayout內的滾動
現在在我的代碼中,我通過編程方式將TableLayouts添加到了LinearLayout(我也嘗試過使用GridViews而不是TableLayouts)。
<LinearLayout
android:id="@+id/layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/PageRadioGroup"
android:layout_alignParentTop="true"
android:layout_marginTop="3dp"
android:orientation="vertical" >
</LinearLayout>
此LinearLayout不可滾動,問題是我有4個表,只有第一個表是可見的。如果我在ScrollView/NestedScrollView中包含LinearLayout,則主父ScrollView將被禁用。
如何維護主滾動視圖內的滾動,保持RelativeLayout結構並同時允許子LinearLayout內的滾動以查看其中的所有表。
這是我的佈局XML
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp" >
<RadioGroup
android:id="@+id/PageRadioGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="19dp"
android:clickable="false"
android:orientation="horizontal" >
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:clickable="false" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="false" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="false" />
</RadioGroup>
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="349dp"
android:layout_above="@+id/PageRadioGroup"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:focusableInTouchMode="true" >
</android.support.v4.view.ViewPager>
<Button
android:id="@+id/btnBack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:text="@string/back"
android:textAllCaps="false" />
<Button
android:id="@+id/btnSave"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:text="@string/save"
android:textAllCaps="false"/>
<Button
android:id="@+id/btnDone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignStart="@+id/btnSave"
android:text="@string/done"
android:textAllCaps="false" />
<LinearLayout
android:id="@+id/layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/PageRadioGroup"
android:layout_alignParentTop="true"
android:layout_marginTop="3dp"
android:orientation="vertical" >
</LinearLayout>
</RelativeLayout>
</ScrollView>
謝謝!
它不是一個好方法,把一個垂直滾動容器垂直滾動容器內:)但你可以嘗試添加機器人:nestedScrollingEnabled =「true」以你的LinearLayout – Prexx
機器人:nestedScrollingEnabled =「真」不工作。有沒有辦法讓LinearLayout可以滾動而不使用內部ScrollView? – Hanaa
問題是:LinearLayout應該是可滾動的嗎?還是有佈局問題? – Prexx