我想要在我的活动布局中滚动视图。我试过很多方面,但没有成功。最后两个按钮重叠。我想在活动布局中添加更多按钮。请给我一些建议摆脱这个问题。
<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>
答案 0 :(得分:1)
你添加了scrollview的第一件事,我瘦了你可能尝试在relativelayout里面添加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="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>