2015-12-18 183 views
0

我在android studio中開發應用程序。我想使我的應用程序響應不同的設備,我有一個佈局問題佈局問題android

首先,我有三個控件一個EditText,TextField,Spinner,當創建片段時,微調器加載數據。所有這些都在GridLayout用下面的代碼:

<GridLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:columnCount="3" 
     android:layout_margin="2sp"> 

     <TextView 
      android:id="@+id/txtHeight" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textAppearance="?android:attr/textAppearanceMedium" 
      android:text="Height" 
      android:textColor="#000000" 
      android:textSize="24sp" 
      android:layout_margin="5sp" /> 

     <EditText 
      android:background="@drawable/custom_edit_text" 
      android:inputType="number" 
      android:id="@+id/editText" 
      android:layout_margin="2sp" 
      android:layout_height="50sp" 
      android:layout_width="120sp"/> 


     <Spinner 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/spinner" 
      android:layout_margin="2sp" 
      /> 

    </GridLayout> 
</LinearLayout> 

我怎樣才能居中控制,而不影響響應式設計,我想是這樣的: Picture1

我已經是問題微調得到更多的空間比其他兩個控件,這是同樣的,當我改變電話的朝向

回答

0

爲什麼使用網格佈局?我認爲這將是更好地使用linearLayoutlayout_width = match_parentlayout_height = 200dp)與水平方向,那麼你指定它的weighSum 3,你把這些意見這裏面linearLayoutlayout_width = 0layout_weight = 1gravity = center

+0

你試過這個嗎? – cylon

+0

感謝您的幫助,它的工作原理。我是Android新手,你可以推薦任何書籍或博客來加速我的學習? – SantiagoGlz

0

只要指定android:layout_width="80dp"等,或只使用

android:layout_weight=0.3 
android:layout_weight=0.3 
android:layout_weight=0.4 

對於視圖