0

我想在我的活動佈局中滾動視圖。我嘗試了很多方式,但沒有取得成功。最後兩個按鈕正在重疊。我想在活動佈局中添加更多按鈕。請給我一些建議,擺脫這個問題。ScrollView在相對佈局不起作用,其影響佈局

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/main" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@color/cream" 
    android:scrollbars="vertical"> 

    <Button 
    android:id="@+id/button7" 
    android:layout_width="70dp" 
    android:layout_height="50dp" 
    android:layout_alignBottom="@+id/Bconfiguration" 
    android:layout_toLeftOf="@+id/Bconfiguration" 
    android:layout_toStartOf="@+id/Bconfiguration" 
    android:background="@drawable/round_button" 
    android:gravity="center_vertical|center_horizontal" 
    android:textColor="#fff" /> 

    <Button 
    android:id="@+id/button8" 
    android:layout_width="70dp" 
    android:layout_height="50dp" 
    android:layout_alignTop="@+id/Bquestions" 
    android:layout_toLeftOf="@+id/Bquestions" 
    android:layout_toStartOf="@+id/Bquestions" 
    android:background="@drawable/round_button" 
    android:gravity="center_vertical|center_horizontal" 
    android:textColor="#fff" /> 

    <Button 
    android:id="@+id/button9" 
    android:layout_width="70dp" 
    android:layout_height="50dp" 
    android:layout_alignTop="@+id/Bscenario" 
    android:layout_toLeftOf="@+id/Bscenario" 
    android:layout_toStartOf="@+id/Bscenario" 
    android:background="@drawable/round_button" 
    android:gravity="center_vertical|center_horizontal" 
    android:textColor="#fff" /> 

    <Button 
    android:id="@+id/button10" 
    android:layout_width="70dp" 
    android:layout_height="50dp" 
    android:layout_alignBottom="@+id/button3" 
    android:layout_toLeftOf="@+id/button3" 
    android:layout_toStartOf="@+id/button3" 
    android:background="@drawable/round_button" 
    android:gravity="center_vertical|center_horizontal" 
    android:textColor="#fff" /> 



</RelativeLayout> 

回答

1
您添加滾動視圖

第一件事,我thinnk你可以嘗試添加里面的RelativeLayout滾動視圖,並試圖因爲滾動視圖僅包含單直接孩子嘗試下面的代碼添加多個按鈕,它是不可能的,你會得到一個想法

<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:fillViewport="true"> 
<RelativeLayout 
    android:id="@+id/main" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@color/cream" 
    android:scrollbars="vertical"> 

    <Button 
     android:id="@+id/button7" 
     android:layout_width="70dp" 
     android:layout_height="50dp" 
     android:layout_alignBottom="@+id/Bconfiguration" 
     android:layout_toLeftOf="@+id/Bconfiguration" 
     android:layout_toStartOf="@+id/Bconfiguration" 
     android:background="@drawable/round_button" 
     android:gravity="center_vertical|center_horizontal" 
     android:textColor="#fff" /> 

    <Button 
     android:id="@+id/button8" 
     android:layout_width="70dp" 
     android:layout_height="50dp" 
     android:layout_alignTop="@+id/Bquestions" 
     android:layout_toLeftOf="@+id/Bquestions" 
     android:layout_toStartOf="@+id/Bquestions" 
     android:background="@drawable/round_button" 
     android:gravity="center_vertical|center_horizontal" 
     android:textColor="#fff" /> 

    <Button 
     android:id="@+id/button9" 
     android:layout_width="70dp" 
     android:layout_height="50dp" 
     android:layout_alignTop="@+id/Bscenario" 
     android:layout_toLeftOf="@+id/Bscenario" 
     android:layout_toStartOf="@+id/Bscenario" 
     android:background="@drawable/round_button" 
     android:gravity="center_vertical|center_horizontal" 
     android:textColor="#fff" /> 

    <Button 
     android:id="@+id/button10" 
     android:layout_width="70dp" 
     android:layout_height="50dp" 
     android:layout_alignBottom="@+id/button3" 
     android:layout_toLeftOf="@+id/button3" 
     android:layout_toStartOf="@+id/button3" 
     android:background="@drawable/round_button" 
     android:gravity="center_vertical|center_horizontal" 
     android:textColor="#fff" /> 



</RelativeLayout> 
</ScrollView> 
+0

也檢出你的ID,你想定位我認爲不存在 – Pavan

+0

@akarsh如果它幫助你,那麼你能接受這個答案還是讓我知道 – Pavan

+0

我想這一點,但最後兩個按鈕重疊。滾動視圖仍然不起作用。 – akarsh