2010-08-21 16 views
7

मैं जो ऐप बना रहा हूं, उसके लिए मैं प्रति पंक्ति 2 अलग-अलग आइकन से बना एक मुख्य मेनू रखने की योजना बना रहा हूं। यह यहां देखे गए ट्विटर मुख्य मेनू लेआउट के समान है: nothxAndroid में मुख्य मेनू लेआउट कैसे सेट करें?

तो मूल रूप से ... मुझे XML सेट अप करने के बारे में कैसे जाना चाहिए? LinearLayout, TableLayout? और फिर, आइकन और टेक्स्ट को समान रूप से दूरी पर रखने के लिए मैं वास्तव में क्या करूँ? मैंने अब तक जो कुछ भी सोच सकता हूं उसकी कोशिश की है और इसका कोई फायदा नहीं हुआ है।

+1

क्यों एक ग्रिड दृश्य की कोशिश नहीं कर रहा? यहां यह दृश्य प्रकार है, मुझे लगता है कि यह किसी अन्य अभिनव सोच के साथ मिलकर मदद कर सकता है .. मुझे लगता है कि वे क्लिक-सक्षम भी हैं, इसलिए आपको बस एक स्विच केस या कुछ ऐसा करना है। – Shouvik

+0

यदि आप इसे सही मानते हैं तो कृपया उत्तर स्वीकार करें। यह दूसरों को एक ही समस्या का सामना करने में मदद करेगा, समाधान को तेजी से ढूंढें। –

उत्तर

7

हाँ GridView & TextView का उपयोग करें (CompoundDrawables के साथ) - मैंने पहले ऐसा किया:

main.xml:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <GridView android:id="@+id/grid" android:numColumns="2" 
     android:horizontalSpacing="20dip" android:verticalSpacing="20dip" 
     android:stretchMode="columnWidth" android:layout_width="fill_parent" android:layout_height="fill_parent" /> 
</LinearLayout> 

MainActivity:

GridView grid = (GridView) findViewById(R.id.grid); 
     grid.setAdapter(new HomeScreenShortcutAdapter()); 
     grid.setOnItemClickListener(new OnItemClickListener() { 

      @Override 
      public void onItemClick(AdapterView<?> parent, View v, int position, 
        long id) { 

       startActivity(i); // Specify activity through Intent i 
      } 
     }); 

public class HomeScreenShortcutAdapter extends BaseAdapter { 



     HomeScreenShortcutAdapter() { 

     } 

     @Override 
     public int getCount() { 
      return 0; 
     } 

     @Override 
     public Object getItem(int position) { 
      return null; 
     } 

     @Override 
     public long getItemId(int position) { 
      return 0; 
     } 

     @Override 
     public View getView(int position, View convertView, ViewGroup parent) { 
      TextView tv; 
      final Object data = getItem(position); 

      if (convertView == null) { 

       tv = new TextView(getApplicationContext()); 
       tv.setGravity(Gravity.CENTER); 

      } else { 
       tv = (TextView) convertView; 
      } 

      Drawable icon = data.icon; 
      CharSequence title = data.title; 

      tv.setCompoundDrawablesWithIntrinsicBounds(
        null, icon, null, null); 
      tv.setText(title); 
      tv.setTag(data); 

      return tv; 
     } 

    } 
संबंधित मुद्दे