【发布时间】:2017-03-19 09:31:19
【问题描述】:
我正在开发一个应用程序,它有 100 个按钮。我想把所有的按钮都放在屏幕上。我正在使用带有所有按钮的 GridLayout,我遇到的问题是按钮正在离开屏幕。
这是代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:id="@+id/content_main"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".MainActivity"
tools:showIn="@layout/app_bar_main"
android:layout_column="1">
<GridLayout
android:id="@+id/GridLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:columnCount="6"
android:rowCount="17"
android:orientation="vertical">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
app:srcCompat="@drawable/numero_1"
android:id="@+id/button1"/>
我的问题是:这可能吗?这是最好的方法吗?
我进行了其他测试,更改了图像的大小。结果不是我预期的标题
不同尺寸图片的结果
正如您在第二张图片中看到的那样,行中的按钮位于屏幕内部,但按钮的位置不对,行的最后一个按钮和屏幕末尾之间有很多空间。
我正在寻找的解决方案是有一个不允许按钮离开屏幕的布局,并且如果屏幕大小不同,它会自动调整按钮和边缘之间的空间大小布局会自动适应屏幕大小。
【问题讨论】:
标签: android autoresize android-gridlayout android-imagebutton