RelativeLayout不显示所有按钮

时间:2014-03-13 11:06:37

标签: android xml android-layout layout relativelayout

我无法将所有按钮都放在屏幕上?屏幕的最后一行半按钮是否已关闭?最终的布局看起来有点不同我已经制作了自定义按钮,大多数按钮都有辅助功能,但我已经简化了代码,以消除所有可能与我的问题没有直接关系的错误。我喜欢按钮来填充和留在屏幕上(我发布了我的布局图片,但我的声誉太低了)

RelativeLayout的

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/MainLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <EditText
        android:id="@+id/result"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="none" />

    <ImageView
        android:id="@+id/sample"
        android:layout_below="@+id/result"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:contentDescription="@string/contentDescriptionImageView"
        android:scaleType="centerInside"
        android:src="@drawable/sample" />

    <Button
        android:id="@+id/b11"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/sample"
        android:layout_margin="0dp"
        android:text="@string/b11" />

    //...buttons

    <Button
        android:id="@+id/b95"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_below="@+id/b85"
        android:layout_margin="0dp"
        android:layout_toRightOf="@+id/b94"
        android:text="@string/b95" />

</RelativeLayout>

的LinearLayout(的LinearLayout + GridLayout的)

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:grid="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <LinearLayout
        android:id="@+id/linearLayoutH1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:weightSum="1.0"
        android:orientation="vertical" >

        <EditText
            android:id="@+id/result"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="none" />

        <ImageView
            android:id="@+id/sample"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:contentDescription="@string/contentDescriptionImageView"
            android:scaleType="centerInside"
            android:src="@drawable/sample" />
    </LinearLayout>

    <GridLayout
        android:id="@+id/GridLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:columnCount="5"
        android:rowCount="9"
        android:useDefaultMargins="false" >

        <Button
            android:id="@+id/b11"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="0dp"
            android:text="@string/b11" />

        //...buttons are the same, I just erased the following RelativeLayout attributes:
-android:layout_below
-android:layout_toRightOf
-android:layout_alignParentBottom

        <Button
            android:id="@+id/b95"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="0dp"
            android:text="@string/b95" />

    </GridLayout>

</LinearLayout>

http://postimg.org/image/wvcl7rfer/eeef02dd/

这里有适合我的解决方案(我还没有尝试过GridView和TableLayout) 它是BrOtherSOul的那个。这是我的代码:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/MainLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
    android:orientation="vertical" >

<EditText
    android:id="@+id/result"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:inputType="none" />

<ImageView
    android:id="@+id/sample"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:contentDescription="@string/contentDescriptionImageView"
    android:scaleType="centerInside"
    android:src="@drawable/sample" />

<LinearLayout
    android:id="@+id/linearLayoutH3"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1" >

    <Button
        android:id="@+id/b11"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="0dp"
        android:text="@string/b11" />

    <Button
        android:id="@+id/b12"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="0dp"
        android:text="@string/b12" />

    <Button
        android:id="@+id/b13"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="0dp"
        android:text="@string/b13" />

    <Button
        android:id="@+id/b14"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="0dp"
        android:text="@string/b14" />

    <Button
        android:id="@+id/b15"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="0dp"
        android:text="@string/b15" />


</LinearLayout>

<LinearLayout
    android:id="@+id/linearLayoutH5"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1" >

    <Button
        android:id="@+id/b21"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="0dp"
        android:text="@string/b21" />

    <Button
        android:id="@+id/b22"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="0dp"
        android:text="@string/b22" />

    <Button
        android:id="@+id/b23"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="0dp"
        android:text="@string/b23" />

    <Button
        android:id="@+id/b24"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="0dp"
        android:text="@string/b24" />

    <Button
        android:id="@+id/b25"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="0dp"
        android:text="@string/b25" />

</LinearLayout>

<LinearLayout
    android:id="@+id/linearLayoutH7"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1" >

    <Button
        android:id="@+id/b31"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="0dp"
        android:text="@string/b31" />

    <Button
        android:id="@+id/b32"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="0dp"
        android:text="@string/b32" />

    <Button
        android:id="@+id/b33"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="0dp"
        android:text="@string/b33" />

    <Button
        android:id="@+id/b34"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="0dp"
        android:text="@string/b34" />

    <Button
        android:id="@+id/b35"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="0dp"
        android:text="@string/b35" />

</LinearLayout>

<LinearLayout
    android:id="@+id/linearLayoutH9"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1" >

    <Button
        android:id="@+id/b41"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="0dp"
        android:text="@string/b41" />

    <Button
        android:id="@+id/b42"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="0dp"
        android:text="@string/b42" />

    <Button
        android:id="@+id/b43"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="0dp"
        android:text="@string/b43" />

    <Button
        android:id="@+id/b44"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="0dp"
        android:text="@string/b44" />

    <Button
        android:id="@+id/b45"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="0dp"
        android:text="@string/b45" />


</LinearLayout>

<LinearLayout
    android:id="@+id/linearLayoutH11"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1" >

    <Button
        android:id="@+id/b51"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="0dp"
        android:text="@string/b51" />

    <Button
        android:id="@+id/b52"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="0dp"
        android:text="@string/b52" />

    <Button
        android:id="@+id/b53"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="0dp"
        android:text="@string/b53" />

    <Button
        android:id="@+id/b54"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="0dp"
        android:text="@string/b54" />

    <Button
        android:id="@+id/b55"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="0dp"
        android:text="@string/b55" />

</LinearLayout>

<LinearLayout
    android:id="@+id/linearLayoutH13"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1" >

    <Button
        android:id="@+id/b61"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="0dp"
        android:text="@string/b61" />

    <Button
        android:id="@+id/b62"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="0dp"
        android:text="@string/b62" />

    <Button
        android:id="@+id/b63"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="0dp"
        android:text="@string/b63" />

    <Button
        android:id="@+id/b64"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="0dp"
        android:text="@string/b64" />

    <Button
        android:id="@+id/b65"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="0dp"
        android:text="@string/b65" />

</LinearLayout>

<LinearLayout
    android:id="@+id/linearLayoutH15"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1" >

    <Button
        android:id="@+id/b71"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="0dp"
        android:text="@string/b71" />

    <Button
        android:id="@+id/b72"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="0dp"
        android:text="@string/b72" />

    <Button
        android:id="@+id/b73"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="0dp"
        android:text="@string/b73" />

    <Button
        android:id="@+id/b74"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="0dp"
        android:text="@string/b74" />

    <Button
        android:id="@+id/b75"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="0dp"
        android:text="@string/b75" />

</LinearLayout>

<LinearLayout
    android:id="@+id/linearLayoutH17"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1" >

    <Button
        android:id="@+id/b81"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="0dp"
        android:text="@string/b81" />

    <Button
        android:id="@+id/b82"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="0dp"
        android:text="@string/b82" />

    <Button
        android:id="@+id/b83"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="0dp"
        android:text="@string/b83" />

    <Button
        android:id="@+id/b84"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="0dp"
        android:text="@string/b84" />

    <Button
        android:id="@+id/b85"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="0dp"
        android:text="@string/b85" />

</LinearLayout>

<LinearLayout
    android:id="@+id/linearLayoutH19"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1" >

    <Button
        android:id="@+id/b91"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="0dp"
        android:text="@string/b91" />

    <Button
        android:id="@+id/b92"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="0dp"
        android:text="@string/b92" />

    <Button
        android:id="@+id/b93"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="0dp"
        android:text="@string/b93" />

    <Button
        android:id="@+id/b94"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="0dp"
        android:text="@string/b94" />

    <Button
        android:id="@+id/b95"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="0dp"
        android:text="@string/b95" />

</LinearLayout>

</LinearLayout>

http://postimg.org/image/ltromjjpp/5ad91d61/

7 个答案:

答案 0 :(得分:1)

您要求GridLayout将其内容包装在纵向一侧。它确实做到了这一点,并且必须超越屏幕才能做到这一点。 GridLayout旨在防止嵌套布局,但看起来您必须完全这样做。尝试放弃GridLayout并为每一行按钮创建一个LinearLayout,所有这些都在LinearLayout中。 我知道它很脏但是......(他们应该支持体重) 对于您运行它的每个屏幕,此解决方案将在垂直方面工作。你可以对宽度做同样的事情(我刚刚解决了垂直问题)

像这样:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/MainLayout"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<EditText
    android:id="@+id/result"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:inputType="none" />

<ImageView
    android:id="@+id/sample"
    android:layout_below="@+id/result"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:contentDescription="@string/contentDescriptionImageView"
    android:scaleType="centerInside"
    android:src="@drawable/sample" />

<LinearLayout
    android:id="@+id/1stRow"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1" >

 //.... Your buttons

<LinearLayout
    android:id="@+id/2ndRow"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1" >

 //.... Buttons again

<LinearLayout
    android:id="@+id/LastRow"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1" >

</LinearLayout>

此致 你的救世主:)

答案 1 :(得分:0)

使用滚动视图dude

        <ScrollView
               xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="fill_parent"
               android:layout_height="fill_parent">
            <RelativeLayout
             android:id="@+id/MainLayout"
             android:layout_width="match_parent"
             android:layout_height="wrap_content" >

        // here u can add your all button or edit text or whatever u want to add just add 

        </ RelativeLayout>
        </ScrollView>

答案 2 :(得分:0)

像这样更新您的布局

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <RelativeLayout
        android:id="@+id/MainLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <EditText
            android:id="@+id/result"
            style="@style/ButtonTextWhite"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="none" />

        <ImageView
            android:id="@+id/sample"
            style="@style/ButtonTextWhite"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/result"
            android:contentDescription="@string/contentDescriptionImageView"
            android:scaleType="centerInside"
            android:src="@drawable/sample" />

        <Button
            android:id="@+id/b11"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/sample"
            android:layout_margin="0dp"
            android:text="@string/b11" />

        <Button
            android:id="@+id/b12"
            style="@style/ButtonTextWhite"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/sample"
            android:layout_margin="0dp"
            android:layout_toRightOf="@+id/b11"
            android:text="@string/b12" />

        <Button
            android:id="@+id/b13"
            style="@style/ButtonTextWhite"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/sample"
            android:layout_margin="0dp"
            android:layout_toRightOf="@+id/b12"
            android:text="@string/b13" />

        <Button
            android:id="@+id/b14"
            style="@style/ButtonTextWhite"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/sample"
            android:layout_margin="0dp"
            android:layout_toRightOf="@+id/b13"
            android:text="@string/b14" />

        <Button
            android:id="@+id/b15"
            style="@style/ButtonTextWhite"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/sample"
            android:layout_margin="0dp"
            android:layout_toRightOf="@+id/b14"
            android:text="@string/b15" />

        <Button
            android:id="@+id/b21"
            style="@style/ButtonTextWhite"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/b11"
            android:layout_margin="0dp"
            android:text="@string/b21" />

        <Button
            android:id="@+id/b22"
            style="@style/ButtonTextWhite"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/b12"
            android:layout_margin="0dp"
            android:layout_toRightOf="@+id/b21"
            android:text="@string/b22" />

        <Button
            android:id="@+id/b23"
            style="@style/ButtonTextWhite"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/b13"
            android:layout_margin="0dp"
            android:layout_toRightOf="@+id/b22"
            android:text="@string/b23" />

        <Button
            android:id="@+id/b24"
            style="@style/ButtonTextWhite"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/b14"
            android:layout_margin="0dp"
            android:layout_toRightOf="@+id/b23"
            android:text="@string/b24" />

        <Button
            android:id="@+id/b25"
            style="@style/ButtonTextBlack"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/b15"
            android:layout_margin="0dp"
            android:layout_toRightOf="@+id/b24"
            android:text="@string/b25" />

        <Button
            android:id="@+id/b31"
            style="@style/ButtonTextWhite"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/b21"
            android:layout_margin="0dp"
            android:text="@string/b31" />

        <Button
            android:id="@+id/b32"
            style="@style/ButtonTextWhite"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/b22"
            android:layout_margin="0dp"
            android:layout_toRightOf="@+id/b31"
            android:text="@string/b32" />

        <Button
            android:id="@+id/b33"
            style="@style/ButtonTextWhite"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/b23"
            android:layout_margin="0dp"
            android:layout_toRightOf="@+id/b32"
            android:text="@string/b33" />

        <Button
            android:id="@+id/b34"
            style="@style/ButtonTextWhite"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/b24"
            android:layout_margin="0dp"
            android:layout_toRightOf="@+id/b33"
            android:text="@string/b34" />

        <Button
            android:id="@+id/b35"
            style="@style/ButtonTextWhite"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/b25"
            android:layout_margin="0dp"
            android:layout_toRightOf="@+id/b34"
            android:text="@string/b35" />

        <Button
            android:id="@+id/b41"
            style="@style/ButtonTextWhite"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/b31"
            android:layout_margin="0dp"
            android:text="@string/b41" />

        <Button
            android:id="@+id/b42"
            style="@style/ButtonTextWhite"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/b32"
            android:layout_margin="0dp"
            android:layout_toRightOf="@+id/b41"
            android:text="@string/b42" />

        <Button
            android:id="@+id/b43"
            style="@style/ButtonTextWhite"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/b33"
            android:layout_margin="0dp"
            android:layout_toRightOf="@+id/b42"
            android:text="@string/b43" />

        <Button
            android:id="@+id/b44"
            style="@style/ButtonTextWhite"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/b34"
            android:layout_margin="0dp"
            android:layout_toRightOf="@+id/b43"
            android:text="@string/b44" />

        <Button
            android:id="@+id/b45"
            style="@style/ButtonTextWhite"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/b35"
            android:layout_margin="0dp"
            android:layout_toRightOf="@+id/b44"
            android:text="@string/b45" />

        <Button
            android:id="@+id/b51"
            style="@style/ButtonTextWhite"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/b41"
            android:layout_margin="0dp"
            android:text="@string/b51" />

        <Button
            android:id="@+id/b52"
            style="@style/ButtonTextWhite"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/b42"
            android:layout_margin="0dp"
            android:layout_toRightOf="@+id/b51"
            android:text="@string/b52" />

        <Button
            android:id="@+id/b53"
            style="@style/ButtonTextWhite"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/b43"
            android:layout_margin="0dp"
            android:layout_toRightOf="@+id/b52"
            android:text="@string/b53" />

        <Button
            android:id="@+id/b54"
            style="@style/ButtonTextWhite"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/b44"
            android:layout_margin="0dp"
            android:layout_toRightOf="@+id/b53"
            android:text="@string/b54" />

        <Button
            android:id="@+id/b55"
            style="@style/ButtonTextBlack"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/b45"
            android:layout_margin="0dp"
            android:layout_toRightOf="@+id/b54"
            android:text="@string/b55" />

        <Button
            android:id="@+id/b61"
            style="@style/ButtonTextWhite"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/b51"
            android:layout_margin="0dp"
            android:text="@string/b61" />

        <Button
            android:id="@+id/b62"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/b52"
            android:layout_margin="0dp"
            android:layout_toRightOf="@+id/b61"
            android:text="@string/b62" />

        <Button
            android:id="@+id/b63"
            style="@style/ButtonTextBlack"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/b53"
            android:layout_margin="0dp"
            android:layout_toRightOf="@+id/b62"
            android:text="@string/b63" />

        <Button
            android:id="@+id/b64"
            style="@style/ButtonTextBlack"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/b54"
            android:layout_margin="0dp"
            android:layout_toRightOf="@+id/b63"
            android:text="@string/b64" />

        <Button
            android:id="@+id/b65"
            style="@style/ButtonTextBlack"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/b55"
            android:layout_margin="0dp"
            android:layout_toRightOf="@+id/b64"
            android:text="@string/b65" />

        <Button
            android:id="@+id/b71"
            style="@style/ButtonTextWhite"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/b61"
            android:layout_margin="0dp"
            android:text="@string/b71" />

        <Button
            android:id="@+id/b72"
            style="@style/ButtonTextBlack"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/b62"
            android:layout_margin="0dp"
            android:layout_toRightOf="@+id/b71"
            android:text="@string/b72" />

        <Button
            android:id="@+id/b73"
            style="@style/ButtonTextBlack"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/b63"
            android:layout_margin="0dp"
            android:layout_toRightOf="@+id/b72"
            android:text="@string/b73" />

        <Button
            android:id="@+id/b74"
            style="@style/ButtonTextBlack"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/b64"
            android:layout_margin="0dp"
            android:layout_toRightOf="@+id/b73"
            android:text="@string/b74" />

        <Button
            android:id="@+id/b75"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/b65"
            android:layout_margin="0dp"
            android:layout_toRightOf="@+id/b74"
            android:text="@string/b75" />

        <Button
            android:id="@+id/b81"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/b71"
            android:layout_margin="0dp"
            android:text="@string/b81" />

        <Button
            android:id="@+id/b82"
            style="@style/ButtonTextBlack"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/b72"
            android:layout_margin="0dp"
            android:layout_toRightOf="@+id/b81"
            android:text="@string/b82" />

        <Button
            android:id="@+id/b83"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/b73"
            android:layout_margin="0dp"
            android:layout_toRightOf="@+id/b82"
            android:text="@string/b83" />

        <Button
            android:id="@+id/b84"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/b74"
            android:layout_margin="0dp"
            android:layout_toRightOf="@+id/b83"
            android:text="@string/b84" />

        <Button
            android:id="@+id/b85"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/b75"
            android:layout_margin="0dp"
            android:layout_toRightOf="@+id/b84"
            android:text="@string/b85" />

        <Button
            android:id="@+id/b91"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_below="@+id/b81"
            android:layout_margin="0dp"
            android:text="@string/b91" />

        <Button
            android:id="@+id/b92"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_below="@+id/b82"
            android:layout_margin="0dp"
            android:layout_toRightOf="@+id/b91"
            android:text="@string/b92" />

        <Button
            android:id="@+id/b93"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_below="@+id/b83"
            android:layout_margin="0dp"
            android:layout_toRightOf="@+id/b92"
            android:text="@string/b93" />

        <Button
            android:id="@+id/b94"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_below="@+id/b84"
            android:layout_margin="0dp"
            android:layout_toRightOf="@+id/b93"
            android:text="@string/b94" />

        <Button
            android:id="@+id/b95"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_below="@+id/b85"
            android:layout_margin="0dp"
            android:layout_toRightOf="@+id/b94"
            android:text="@string/b95" />
    </RelativeLayout>

</ScrollView>

答案 3 :(得分:0)

对每三个按钮使用linearlayout,这样您就可以轻松满足您的要求。

<linearlayout

orientation=horizantal>
<button1>
<button2>
<button3>

</linearlayout>

像这样使用......

答案 4 :(得分:0)

只需在相对布局

之前添加滚动视图

答案 5 :(得分:0)

只需在ScrollView中包装相对布局。

答案 6 :(得分:0)

第一个:

永远不要使用XML在Layout中创建大量按钮。如果您想生成巨大的按钮,请执行dynamically或使用GridView

第二名: 如果你在Xml中创建了大量的按钮,那就别忘了使用ScrollView

 <?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <RelativeLayout
        android:id="@+id/MainLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
            // Your buttons

    </RelativeLayout>

</ScrollView>
相关问题