1

私はそれがばかげた質問かもしれないことを知っています...しかし、私はAndroidが初めてです...プロジェクトにグリッドビューレイアウトがあり、コードを書くために「Android開発者」コードを使用しました...したがって、のxmlコードレイアウトは次のようになります。

   <?xml version="1.0" encoding="utf-8"?>
<GridView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/gridview"
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"
    android:columnWidth="90dp"
    android:numColumns="auto_fit"
    android:verticalSpacing="10dp"
    android:horizontalSpacing="10dp"
    android:stretchMode="columnWidth"
    android:gravity="center"
/>

今、グリッドビューにボタンを追加したいのですが、ドラッグ アンド ドロップではできません...ボタンを追加する xml コードを記述しようとしましたが、次のエラーが発生しました:「XML ファイルにエラーがあります。 : ビルドを中止します。" 誰でもこの問題で私を助けることができますか?

4

1 に答える 1

1

Buttonより下にしたい場合は、次のGridViewようにします。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="center"
    android:orientation="vertical" >

    <GridView
        android:id="@+id/gridFriends"
        android:layout_width="fill_parent"
        android:layout_height="0dip"
        android:layout_weight="1"
        android:clipChildren="true"
        android:columnWidth="100dp"
        android:gravity="center"
        android:numColumns="auto_fit"
        android:scrollbars="none"
        android:stretchMode="columnWidth" >
    </GridView>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:paddingBottom="5dp"
        android:paddingLeft="9dp"
        android:paddingRight="9dp"
        android:paddingTop="5dp" >

        <ImageButton
            android:id="@+id/imgbtnDemo"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|center"
            android:background="@null"
            android:gravity="center"
            android:src="@drawable/ic_contact_picture" >
        </ImageButton>
    </LinearLayout>

</LinearLayout>

Buttonのすべてのセルに が必要な場合は、アダプタをGridView使用するカスタムを使用する必要があります。GridViewのカスタム セルの XML スニペットの例GridView:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mainContainer"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="5dp" >

    <FrameLayout
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:gravity="center" >

        <ImageView
            android:id="@+id/imgProfilePicture"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:adjustViewBounds="true"
            android:scaleType="centerCrop"
            android:src="@null" />

        <ImageButton
            android:id="@+id/imgbtnDemo"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|center"
            android:background="@null"
            android:gravity="center"
            android:src="@drawable/ic_contact_picture" >
        </ImageButton>
    </FrameLayout>

</RelativeLayout>

注:投稿の XMLS スニペットでは、ImageButton's. それらと必要な属性を の属性に変更しますButton。これは単なるです。ただし、ドットを接続できるはずです。;-)

カスタムの概念に精通している場合はListViews、いくつかの変更を加えることで、カスタムも実装できGridViewます。ListViewsカスタムまたはに慣れていない場合はGridViews、次のチュートリアルに従ってカスタムを作成する方法を確認してGridViewください .

または、このGoogle 検索を使用して、カスタム に関するその他のチュートリアルを参照してくださいGridView's

そして、これは SO に関する私の回答へのリンクです。それは完全な解決策を持っています。目的に合ったロジックを使用してください。

于 2013-07-14T11:11:13.390 に答える