क्या चित्रों की ग्रिड के बजाय ग्रिडव्यू बनाना संभव है, उनमें से प्रत्येक के नीचे एक छोटी छवि बटन के साथ चित्रों का ग्रिड?प्रत्येक मान के लिए लेआउट (छविदृश्य + छविबटन) के साथ ग्रिडव्यू
उत्तर
संक्षिप्त उत्तर: हां। GridView
में आपके पास ImageView
और ImageButton
हो सकता है।
लांग जवाब:
आप स्वाभाविक रूप से उस उद्देश्य के लिए एक कस्टम GridView
बनाना पड़ेगा।
उदाहरण के लिए:
एक एक्सएमएल जो कंटेनर GridView
, कहते हैं का आयोजन करेगा, grid.xml
बनाएँ:
<GridView
android:id="@+id/gridFriends"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clipChildren="true"
android:columnWidth="100dp"
android:fastScrollEnabled="true"
android:gravity="center"
android:numColumns="auto_fit"
android:stretchMode="columnWidth" >
</GridView>
और,, GridView
की सामग्री को परिभाषित करने के लिए एक और एक्सएमएल लेआउट जो आयोजन करेगा बनाने ImageView
और ImageButton
। कहो, grid_items.xml
:
<?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>
अंत में, यदि आप कुछ संशोधनों के साथ, कस्टम ListViews
की अवधारणा से परिचित हैं, तो आप भी एक कस्टम GridView
लागू करने के लिए सक्षम हो जाएगा। यदि आप कस्टम ListViews
या GridViews
से परिचित नहीं हैं, तो कस्टम GridView
: http://www.coderzheaven.com/2012/02/29/custom-gridview-in-android-a-simple-example/ बनाने के तरीके को देखने के लिए इस ट्यूटोरियल का पालन करें। या इस पर अधिक ट्यूटोरियल के लिए इस Google Search का उपयोग करें।
एक महत्वपूर्ण बात यहाँ हो सकता है, अगर आप ImageButton's
जरूरत है एक समारोह करने के लिए ताकि उन पर क्लिक कर रहे हैं, onClickListener
Adapter
में सेटअप करने की आवश्यकता होगी।
GridView
Views
का ग्रिड दिखाता है। यह कुछ भी दिखा सकता है जो View
वर्ग को बढ़ाता है। यह LinearLayout
को ImageView
और ImageButton
के साथ दिखा सकता है।
धन्यवाद, यह साइट: http://www.coderzheaven.com/2012/02/29/custom-gridview-in-android-a-simple-example/ + xml की आपने मुझे करने में बहुत मदद की मेरा कस्टम ग्रिडव्यू। बहुत अच्छा जवाब –
@rosualin: आपका स्वागत है। मदद करने में खुशी हुई। :-) –
मैं grid_items में सापेक्ष लेआउट कैसे बढ़ा सकता हूं? मुझे यह अपवाद मिल रहा है: java.lang.ClassCastException: android.widget.FrameLayout $ लेआउट पैराम को android.widget.AbsListView $ लेआउट पैराम – Pria