2013-10-21 62 views
1

http://i.imgur.com/Zt5ftxe.png我將如何在android應用程序中創建此應用程序?

我想重新創建一個android應用程序,但我不知道從哪裏開始。 我希望圖標可以點擊並導致不同的屏幕。 GridLayout會這樣做嗎?

我跟着一個教程,但它只處理圖像,不會導致一個單獨的屏幕。

+0

你可以谷歌一點imagebuttons並完成它:)。快樂的編碼。這是一個小提示,可以幫助 –

回答

0

你想要的更像是DashBoard。 在儀表板中,您可以爲用戶提供一系列選擇以在主屏幕中進行選擇。

檢查this了... 它一定會幫助你

0

使用的GridView可以做到easily.you可以實現使用的GridView聽者方法來調用單獨的屏幕項目單擊

gridView.setOnItemClickListener(new OnItemClickListener() 
{ 
    public void onItemClick(AdapterView<?> parent, View v, 
       int position, long id) 
{ 

     //call Intent based on position 

    } 

}); 

看到this

0

從視覺上來說,你可以用GridLayout來創建這個結構,是的。

如果您希望圖標可點擊,您必須在GridLayout的每個元素上執行setOnItemClickListener()。要做到這一點,創建一個擴展BaseAdapter並將其設置爲您的GridLayout的適配器將非常好。

本教程是很好解釋IMO做你想做什麼:http://www.androidhive.info/2012/02/android-gridview-layout-tutorial/

0

試試這個

GridView oGridView = (GridView)findViewById(R.id.services_gv); 
oGridView.setOnItemClickListener(new OnItemClickListener() 
    { 

     @Override 
     public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, 
       long arg3) 
     { 
      // TODO Auto-generated method stub 
      Intent oIntent = new Intent(YourcurrentActivity.this, NewActivityName.class); 
      startActivity(oIntent); 



     } 
    }); 

而在Android清單

<activity 
     android:name="NewActivityName" 
     > 
    </activity> 
0

您可以使用GridView如下:

1 grid_layout.xml

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

    </GridView> 

2. ImageAdapter

public class ImageAdapter extends BaseAdapter { 
    private Context mContext; 

    // Keep all Images in array 
    public Integer[] mThumbIds = { 
      R.drawable.pic_1, R.drawable.pic_2, 
      R.drawable.pic_3, R.drawable.pic_4, 
      R.drawable.pic_5, R.drawable.pic_6    
    }; 

    // Constructor 
    public ImageAdapter(Context c){ 
     mContext = c; 
    } 

    @Override 
    public int getCount() { 
     return mThumbIds.length; 
    } 

    @Override 
    public Object getItem(int position) { 
     return mThumbIds[position]; 
    } 

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

    @Override 
    public View getView(int position, View convertView, ViewGroup parent) { 
     ImageView imageView = new ImageView(mContext); 
     imageView.setImageResource(mThumbIds[position]); 
     imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); 
     imageView.setLayoutParams(new GridView.LayoutParams(70, 70)); 
     return imageView; 
    } 

} 

3。AndroidGridLayoutActivity

public class AndroidGridLayoutActivity extends Activity { 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.grid_layout); 

     GridView gridView = (GridView) findViewById(R.id.grid_view); 

     // Instance of ImageAdapter Class 
     gridView.setAdapter(new ImageAdapter(this)); 
     gridview.setOnItemClickListener(new AdapterView.OnItemClickListener() { 
     public void onItemClick(AdapterView<?> parent, View v, int position, long id){ 
     Toast.makeText(AndroidGridLayoutActivity.this, "" + position,Toast.LENGTH_SHORT).show(); 
     } 
     }); 
    } 
} 

以下是好GridView教程鏈接:

  1. AndroidHive

  2. Mkyong

0

在佈局和SE只需要用6張圖片t點擊他們的聆聽者

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/resultLayout" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" > 

    <LinearLayout 
     android:id="@+id/linearLayout2" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="horizontal" > 

     <ImageView 
      android:id="@+id/id1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:background="@drawable/ic_launcher" /> 

     <ImageView 
      android:id="@+id/id1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:background="@drawable/ic_launcher" /> 

     <ImageView 
      android:id="@+id/id1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:background="@drawable/ic_launcher" /> 
    </LinearLayout> 
<LinearLayout 
     android:id="@+id/linearLayout2" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="horizontal" > 

     <ImageView 
      android:id="@+id/id1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:background="@drawable/ic_launcher" /> 

     <ImageView 
      android:id="@+id/id1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:background="@drawable/ic_launcher" /> 

     <ImageView 
      android:id="@+id/id1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:background="@drawable/ic_launcher" /> 
    </LinearLayout> 
</LinearLayout> 
相關問題