首页 > 解决方案 > 屏幕外的按钮 - Android

问题描述

我需要帮助...

我试图在buttonsa 内构建 3 个对齐的 1 行和 3 列GridLayout,并且看起来它可以正常工作,但我认为我没有做对,因为如果更改按钮 ( textSize)GridLayout和按钮内的文本大小正在走出屏幕。我认为我设置了layout_witdh和/或layout_height错误,但我不确定。

谁能帮我?谢谢 :)

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    android:background="@drawable/background"
    tools:context="com.markus.tssproject.MainActivity">

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

        <GridLayout
            android:layout_width="match_parent"
            android:layout_height="110dp"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_marginBottom="5dp"
            android:layout_marginRight="5dp"
            android:layout_marginLeft="5dp"
            android:columnCount="3"
            android:rowCount="1">

            <Button
                android:id="@+id/id0"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_column="0"
                android:layout_columnWeight="1"
                android:layout_gravity="fill"
                android:layout_marginRight="3dp"
                android:layout_row="0"
                android:layout_rowWeight="1"
                android:padding="30dp"
                android:tag="0"
                android:text="test tested testing"
                android:textSize="20sp" />

            <Button
                android:id="@+id/open1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginRight="3dp"
                android:layout_column="1"
                android:layout_columnWeight="1"
                android:layout_gravity="fill"
                android:layout_row="0"
                android:layout_rowWeight="1"
                android:padding="30dp"
                android:tag="1"
                android:text="test tested testing"
                android:texSize="20sp" />

            <Button
                android:id="@+id/open2"
                android:layout_width="wrap_content"
                android:layout_column="2"
                android:layout_height="wrap_content"
                android:layout_columnWeight="1"
                android:layout_gravity="fill"
                android:layout_row="0"
                android:layout_rowWeight="1"
                android:padding="30dp"
                android:tag="2"
                android:text="teste tested testing"/>

        </GridLayout>
    </RelativeLayout>
</LinearLayout>

标签: androidandroid-layoutandroid-gridlayout

解决方案


在每个按钮中更改以下内容

android:layout_width="0dip"
android:layout_weight ="1"

你可以自己做LinearLayout,不需要网格布局


推荐阅读