我想要更多可以通过滚动视图访问的按钮

时间:2016-08-15 09:04:44

标签: android

目前有9个按钮,我想添加一些具有相同高度和宽度以及边距的按钮,这些按钮可以通过滚动视图显示在这9个按钮下面。如果有人能帮我修复这些问题,我将非常感谢。

这是我的子xml文件: -

  
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1.5"
android:background="@drawable/heroes_2"
android:id="@+id/sub_m"
 >
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="0.5"
    android:orientation="horizontal"
    android:weightSum="1.5">
    <ImageButton
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="0.5"
        android:src="@drawable/i"
        android:background="@android:color/transparent"
        android:onClick="iron"
        />
    <ImageButton
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="0.5"
        android:src="@drawable/image_2"
        android:background="@android:color/transparent"
        android:onClick="captain"
        />
    <ImageButton
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="0.5"
        android:src="@drawable/h"
        android:background="@android:color/transparent"
        android:onClick="hulk"
        />

   </LinearLayout>
   <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="0.5"
    android:orientation="horizontal"
    android:weightSum="3">
    <ImageButton
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:src="@drawable/d"
        android:background="@android:color/transparent"
        android:onClick="dead"
        />
    <ImageButton
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:src="@drawable/w"
        android:background="@android:color/transparent"
        android:onClick="wolverine"
        />
    <ImageButton
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:src="@drawable/t"
        android:background="@android:color/transparent"
        android:onClick="thor"
        />
  </LinearLayout>
  <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="0.5"
    android:orientation="horizontal"
    android:weightSum="3">
    <ImageButton
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:src="@drawable/v"
        android:background="@android:color/transparent"
        android:onClick="vision"
        />
    <ImageButton
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:src="@drawable/b"
        android:background="@android:color/transparent"
        android:onClick="bucky"
        />
    <ImageButton
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:src="@drawable/s"
        android:background="@android:color/transparent"
        android:onClick="spider"
        />

   </LinearLayout>



   </LinearLayout>

1 个答案:

答案 0 :(得分:0)

如果你想要更多间距添加填充,你也可以添加边距

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/colorAccent"
    >
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:weightSum="1.5"
        android:paddingTop="30dp"
        android:paddingBottom="30dp"           
        >
        <ImageButton
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="0.5"
            android:src="@drawable/a"
            android:background="@android:color/transparent"
            android:onClick="iron"
            />
        <ImageButton
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="0.5"
            android:src="@drawable/b"
            android:background="@android:color/transparent"
            android:onClick="captain"
            />
        <ImageButton
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="0.5"
            android:src="@drawable/c"
            android:background="@android:color/transparent"
            android:onClick="hulk"
            />

    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="30dp"
        android:paddingBottom="30dp"
        android:orientation="horizontal"
        android:weightSum="3">
        <ImageButton
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:src="@drawable/a"
            android:background="@android:color/transparent"
            android:onClick="dead"
            />
        <ImageButton
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:src="@drawable/b"
            android:background="@android:color/transparent"
            android:onClick="wolverine"
            />
        <ImageButton
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:src="@drawable/c"
            android:background="@android:color/transparent"
            android:onClick="thor"
            />
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="30dp"
        android:paddingBottom="30dp"
        android:orientation="horizontal"
        android:weightSum="3">
        <ImageButton
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:src="@drawable/a"
            android:background="@android:color/transparent"
            android:onClick="vision"
            />
        <ImageButton
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:src="@drawable/b"
            android:background="@android:color/transparent"
            android:onClick="bucky"
            />
        <ImageButton
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:src="@drawable/c"
            android:background="@android:color/transparent"
            android:onClick="spider"
            />

    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="30dp"
        android:paddingBottom="30dp"
        android:orientation="horizontal"
        android:weightSum="3">
        <ImageButton
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:src="@drawable/a"
            android:background="@android:color/transparent"
            android:onClick="vision"
            />
        <ImageButton
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:src="@drawable/b"
            android:background="@android:color/transparent"
            android:onClick="bucky"
            />
        <ImageButton
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:src="@drawable/c"
            android:background="@android:color/transparent"
            android:onClick="spider"
            />

    </LinearLayout>
</LinearLayout>
    </ScrollView>