我用GridLayout制作了一个Soundboard。这是它应该是什么样子,以及它在我的华为P8 Lite上的外观:https://gyazo.com/2a08bcd731fb1cfeb07e72f75bc05e7e如何使用GridLayout?
这就是它在我的朋友的Bluestacks,Noxplayer和Device上的外观。
https://gyazo.com/84d878061234c25ae872d4ed2491f2f4
这里IST的XML代码:(这与仅2行按钮的一个例子,normaly有100行)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<GridLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/button1"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:text="Button"/>
<Button
android:id="@+id/Button2"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:text="Button"/>
<Button
android:id="@+id/Button3"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:layout_column="1"
android:layout_row="1"
android:text="Button"/>
<Button
android:id="@+id/Button4"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:layout_column="0"
android:layout_row="1"
android:text="Button"/>
</GridLayout>
</ScrollView>
我想问题各自的这两条线按钮
android:layout_width="100dp"
android:layout_height="100dp"
如果我将它们都设置为“fill_parent”,则按钮会伸出屏幕。
我该如何解决这个问题? 请让我看看正确的代码,因为我的英语很糟糕,而且我是Android Studio的新手。