3

次のコードで、linearlayout の gridview の下にボタンを追加しようとしました。しかし、アプリを実行すると、ボタン項目がないグリッドビューしか表示されません。基本的な間違いかもしれませんが、私には見えません。

<?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="horizontal"
            android:background="#2a2a2a"
         >
            <GridView 
                    android:id="@+id/grid_view"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:columnWidth="150dp"
                    android:numColumns="auto_fit"
                    android:horizontalSpacing="10dp"
                    android:verticalSpacing="10dp"
                    android:stretchMode="columnWidth"
                    android:gravity="center"></GridView>
            <Button 
                    android:id="@+id/button1" 
                    android:layout_width="wrap_content" 
                    android:layout_height="50dp" 
                    android:text="@string/cam_string" />

    </LinearLayout>
4

2 に答える 2

6

の向きを に変更しLinearLayoutますvertical。GridView がすべての水平方向のスペースを占めるため、Button が表示されていないと思われます。LinearLayout は、表示されていない画面外の場所に Button を追加します。layout_heightまた、GridView の を "0dip" に変更し、`android:layout_weight=1' 属性を指定して、ボタンが占有する以外のすべてのスペースを埋めることもできます。

于 2013-06-20T17:18:34.510 に答える
2

他の人が提案したソリューション以外に、相対レイアウトを使用して別の方法を試すことができます。

RelativeLayoutLinearLayout の代わりに、この目的で を使用できます。

         <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:background="#2a2a2a" >

          <GridView 
                android:id="@+id/grid_view"
                android:layout_above="@+id/button1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:columnWidth="150dp"
                android:numColumns="auto_fit"
                android:horizontalSpacing="10dp"
                android:verticalSpacing="10dp"
                android:stretchMode="columnWidth"
                android:gravity="center"></GridView>
           <Button
               android:id="@+id/button1"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:layout_alignParentBottom="true"
               android:layout_centerHorizontal="true"
               android:text="@string/cam_string" />

          </RelativeLayout>
于 2013-06-20T17:23:40.517 に答える