2014-04-07 84 views
0

我想創建在網格視圖(每行3-按鈕)如何在gridview中創建按鈕?

XMLcode: 

<GridLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:id="@+id/GridLayout1" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:columnCount="3" 
android:orientation="horizontal" 
tools:context=".GridXMLActivity" > 

<Button 
    android:id="@+id/button1" 
    android:layout_gravity="left|top" 
    android:text="Button" /> 

<Button 
    android:id="@+id/button2" 
    android:layout_gravity="left|top" 
    android:text="Button" /> 

<Button 
    android:id="@+id/button3" 
    android:layout_gravity="left|top" 
    android:text="Button" /> 

</GridLayout> 

我想要修改該按鈕進入圓角正方形按鈕像在下面的下列鏈接的按鈕。我不是問如何讓一個按鈕的角落變圓。 我想爲每個帶有文本的按鈕獲得圓角方形點擊背景。 爲每個按鈕創建單獨的線性佈局是個好主意嗎?

檢查這些例子 https://www.flickr.com/photos/[email protected]/13697400685 https://www.flickr.com/photos/[email protected]/13697229355

+1

一個'GridView'不是'GridLayout' – donfuxx

回答

0

您可以作出這樣的佈局,並根據您的具體reqirement管理..

<?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:background="@drawable/background" 
     android:orientation="horizontal" 
     android:weightSum="6" > 

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:layout_margin="10dp" 
      android:background="@color/white" > 

      <LinearLayout 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:layout_weight="3" 
       android:orientation="vertical" > 

       <LinearLayout 
        android:id="@+id/layout_Dashboard" 
        android:layout_width="fill_parent" 
        android:layout_height="match_parent" 
        android:layout_margin="2dp" 
        android:layout_weight="1" 
        android:background="@drawable/home_bg" 
        android:gravity="center" 
        android:orientation="vertical" > 

        <ImageView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_gravity="center" 
         android:src="@drawable/exam_logo" /> 

        <TextView 
         style="@style/HOME_SCREEN_FONT" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_gravity="center" 
         android:text="DeshBoard" /> 
       </LinearLayout> 

       <LinearLayout 
        android:id="@+id/layout_MyExam" 
        android:layout_width="fill_parent" 
        android:layout_height="match_parent" 
        android:layout_margin="2dp" 
        android:layout_weight="1" 
        android:background="@drawable/home_bg" 
        android:gravity="center" 
        android:orientation="vertical" > 

        <ImageView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_gravity="center" 
         android:src="@drawable/exam_logo" /> 

        <TextView 
         style="@style/HOME_SCREEN_FONT" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_gravity="center" 
         android:text="MyExam" /> 
       </LinearLayout> 


      </LinearLayout> 

      <LinearLayout 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:layout_weight="3" 
       android:orientation="vertical" > 

       <LinearLayout 
        android:id="@+id/layout_AboutUs" 
        android:layout_width="fill_parent" 
        android:layout_height="match_parent" 
        android:layout_margin="2dp" 
        android:layout_weight="1" 
        android:background="@drawable/home_bg" 
        android:gravity="center" 
        android:orientation="vertical" > 

        <ImageView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_gravity="center" 
         android:src="@drawable/exam_logo" /> 

        <TextView 
         style="@style/HOME_SCREEN_FONT" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_gravity="center" 
         android:text="About Us" /> 
       </LinearLayout> 

       <LinearLayout 
        android:id="@+id/layout_ContactUs" 
        android:layout_width="fill_parent" 
        android:layout_height="match_parent" 
        android:layout_margin="2dp" 
        android:layout_weight="1" 
        android:background="@drawable/home_bg" 
        android:gravity="center" 
        android:orientation="vertical" > 

        <ImageView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_gravity="center" 
         android:src="@drawable/exam_logo" /> 

        <TextView 
         style="@style/HOME_SCREEN_FONT" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_gravity="center" 
         android:text="Contact Us" /> 
       </LinearLayout> 
      </LinearLayout> 

      <LinearLayout 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:layout_weight="3" 
       android:orientation="vertical" > 

       <LinearLayout 
        android:id="@+id/layout_AboutUs" 
        android:layout_width="fill_parent" 
        android:layout_height="match_parent" 
        android:layout_margin="2dp" 
        android:layout_weight="1" 
        android:background="@drawable/home_bg" 
        android:gravity="center" 
        android:orientation="vertical" > 

        <ImageView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_gravity="center" 
         android:src="@drawable/exam_logo" /> 

        <TextView 
         style="@style/HOME_SCREEN_FONT" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_gravity="center" 
         android:text="About Us" /> 
       </LinearLayout> 

       <LinearLayout 
        android:id="@+id/layout_ContactUs" 
        android:layout_width="fill_parent" 
        android:layout_height="match_parent" 
        android:layout_margin="2dp" 
        android:layout_weight="1" 
        android:background="@drawable/home_bg" 
        android:gravity="center" 
        android:orientation="vertical" > 

        <ImageView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_gravity="center" 
         android:src="@drawable/exam_logo" /> 

        <TextView 
         style="@style/HOME_SCREEN_FONT" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_gravity="center" 
         android:text="Contact Us" /> 
       </LinearLayout> 
      </LinearLayout> 
     </LinearLayout> 

    </LinearLayout>