2017-03-08 28 views
0

GridLayoutを使用してSoundboardを作成しました。これはどのように見えるか、Huawei P8 Liteでどのように見えるかです:https://gyazo.com/2a08bcd731fb1cfeb07e72f75bc05e7eGridLayoutの使用方法を教えてください。

これは、Bluestacks、Noxplayer、およびDeviceを私の友人から見た方法です。

XMLコードISTここ

https://gyazo.com/84d878061234c25ae872d4ed2491f2f4

:(これはボタンのわずか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> 

私はこの問題は、各次の2行であると思いますボタン

android:layout_width="100dp" 
    android:layout_height="100dp" 

「fill_parent」に設定すると、ボタンが画面からずれることがあります。

どうすればこの問題を解決できますか? 私は正しいコードを表示してください。私の英語はとても悪く、私はAndroid Studioで初めてです。

答えて

0

いいえいいえGridViewを正しく使用していません。
GridViewはAdapterViewです。つまり、XMLでその子を定義するのではなく、可視になると子を作成および設定するJavaコードのAdapterを渡す必要があります。

GridView hereについて説明する完全なAndroidデベロッパーページがあります。

0

画面サイズの半分まで幅を設定するというトリックがあります。

<ScrollView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
    <LinearLayout 
     android: id="@+id/adjustment_linlayout" 
     android:layout_height="wrap_content" 
     android:layout_width="match_parent" 
     android:orientation="horizontal"> 
       <View 
        android:id="@+id/view1" 
        android: layout_width="match_parent" 
        android:layout_height="0dp" 
        android:layout_weight="1"/> 
        <View 
        android:id="@+id/view2" 
        android: layout_width="match_parent" 
        android:layout_height="0dp" 
        android:layout_weight="1"/> 
    </LinearLayout> 

    <GridLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <Button 
      android:id="@+id/button1" 
      android:layout_width="@id/view1" 
      android:layout_height="100dp" 
      . 
      . 
      . 
</GridLayout> 

あなたはそれ以外のボタンは、グリッド全体をカバーするか、またはまったく表示されませんいくつかのディップ値とlayout_height設定する必要があります。

しかし、最良の方法はPercentRelativeLayoutを使用することです。https://developer.android.com/reference/android/support/percent/PercentRelativeLayout.html

関連する問題