我用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的新手。