2015-09-23 184 views
0

好吧我試圖創建一個屏幕上有很多按鈕,顯然我用盡了空間,所以我將我的佈局設置爲一個ScrollView,並在其下面放置了一個相對佈局,然後將所有的按鈕放在裏面。ScrollView不滾動?

繼承人的代碼:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" 
android:layout_height="1000dp" android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
android:paddingBottom="@dimen/activity_vertical_margin" 
android:fillViewport="true" 
tools:context="com.cecode.www.gjcode.MainTypes" 
android:animateLayoutChanges="true"> 

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Options Menu(placeholder)" 
     android:id="@+id/optionsBtn" 
     android:layout_alignParentTop="true" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" /> 

    <Button 
     android:layout_width="400dp" 
     android:layout_height="80dp" 
     android:text="Top Text" 
     android:id="@+id/button1" 
     android:layout_marginTop="110dp" 
     android:layout_alignParentTop="true" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     /> 

    <Button 
     android:layout_width="400dp" 
     android:layout_height="80dp" 
     android:text="placeholder text" 
     android:id="@+id/button2" 
     android:layout_marginTop="20dp" 
     android:layout_below="@+id/button1" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" /> 

    <Button 
     android:layout_width="400dp" 
     android:layout_height="80dp" 
     android:text="placeholder text" 
     android:id="@+id/button3" 
     android:layout_marginTop="20dp" 
     android:layout_below="@+id/button2" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" /> 

    <Button 
     android:layout_width="400dp" 
     android:layout_height="80dp" 
     android:text="placeholder text" 
     android:id="@+id/button4" 
     android:layout_marginTop="20dp" 
     android:layout_below="@+id/button3" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" /> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:text="mid text" 
     android:id="@+id/textView3" 
     android:layout_below="@+id/button4" 
     android:layout_alignRight="@+id/optionsBtn" 
     android:layout_alignEnd="@+id/optionsBtn" 
     android:layout_marginTop="37dp" /> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:text="bottom text" 
     android:id="@+id/textView4" 
     android:layout_alignParentBottom="true" 
     android:layout_alignLeft="@+id/textView3" 
     android:layout_alignStart="@+id/textView3" /> 

</RelativeLayout> 

</ScrollView> 

繼承人的畫面'的截圖

Scrollview screenshot

我的問題是,當我測試這種設備上也不會滾過文本中期點,所以我不能到底部文本位。謝謝!

回答

2

更換

android:layout_height="1000dp" 

android:layout_height="match_parent" 

,讓我知道,如果它

OK按照指定的按照您的要求,您可以用verticla方向和中旬之間使用的LinearLayout底部文本把另一個線性佈局與wrap_content高度添加按鈕,如果你想添加按鈕之前一些空間,你可以指定minheight佈局看看以下代碼

<ScrollView 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:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
android:paddingBottom="@dimen/activity_vertical_margin" 
android:fillViewport="true" 
tools:context="com.cecode.www.gjcode.MainTypes" 
android:animateLayoutChanges="true"> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:orientation="vertical" 
    android:gravity="center" 
     android:layout_height="match_parent"> 

    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Options Menu(placeholder)" 
     android:id="@+id/optionsBtn" 
     /> 

    <Button 
     android:layout_width="400dp" 
     android:layout_height="80dp" 
     android:text="Top Text" 
     android:id="@+id/button1" 
     android:layout_marginTop="110dp" 

     /> 

    <Button 
     android:layout_width="400dp" 
     android:layout_height="80dp" 
     android:text="placeholder text" 
     android:id="@+id/button2" 
     android:layout_marginTop="20dp" 
     /> 

    <Button 
     android:layout_width="400dp" 
     android:layout_height="80dp" 
     android:text="placeholder text" 
     android:id="@+id/button3" 
     android:layout_marginTop="20dp" 
     /> 

    <Button 
     android:layout_width="400dp" 
     android:layout_height="80dp" 
     android:text="placeholder text" 
     android:id="@+id/button4" 
     android:layout_marginTop="20dp" 
     /> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:text="mid text" 
     android:id="@+id/textView3" 
     /> 

    <LinearLayout android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:minHeight="50dp" 
      android:orientation="vertical"> 
     <!-- add your button here --> 
    </LinearLayout> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:text="bottom text" 
     android:id="@+id/textView4" 
     /> 

</LinearLayout> 
</ScrollView> 
+0

當我這樣做時,底部的文字會回到底部屏幕,中間文本和底部文本之間的所有空間都將丟失。這個想法是Mid和Bottom文本之間的空間將被按鈕佔據。 – ParagonTime

+0

我不明白你想達到的中間和底部文本之間的空間是固定的,或者你想添加一些項目那裏或其他 – Pavan

+0

好吧,我想要做的是添加按鈕之間的空間從中間到底部(並擴大它如果我需要更多的按鈕),他們會向下滾動查看所述按鈕。 – ParagonTime

1

確實很難滿足您的要求。現在讓我解釋它是如何工作的。 ScrollView沒有給出確切的高度,所以當你爲相對佈局設置match_parent時,我想它會爲這個視圖設置最大高度 - Integer.MAX_VALUE。這就是爲什麼Android Studio會警告您將match_parent更改爲wrap_content。 如果您在底部需要此視圖 - 請在運行時設置底部視圖的邊距。