2014-12-08 5 views
0

У меня есть некоторые проблемы. Я хочу сделать файл ресурсов макета Android с помощью GridLayout. Я много пробовал, но результата нет. Я хочу сделать это с помощью GridLayout.Расположение кнопок Android в GridLayout

Посмотрите на мой XML макет

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:orientation="vertical" 
       android:layout_width="match_parent" 
       android:background="@drawable/how_we_perform_background" 
       android:layout_height="match_parent"> 
    <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:textSize="45sp" 
      android:gravity="center" 
      android:text="How are We performing?"/> 
    <GridLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:numColumns="5"> 
     <Button 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:background="@drawable/selector_smile1" 
       android:layout_column="1" 
       android:layout_row="1"/> 
     <Button 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:background="@drawable/selector_smile2" 
       android:layout_column="2" 
       android:layout_row="1"/> 
     <Button 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:background="@drawable/selector_smile3" 
       android:layout_column="3" 
       android:layout_row="1"/> 
     <Button 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:background="@drawable/selector_smile4" 
       android:layout_column="4" 
       android:layout_row="1"/> 
     <Button 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:background="@drawable/selector_smile5" 
       android:layout_column="5" 
       android:layout_row="1"/> 

     <ImageView 
       android:layout_gravity="center" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:src="@drawable/under_smile_image" 
       android:layout_column="1" 
       android:layout_row="2"/> 
     <ImageView 
       android:layout_gravity="center" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:src="@drawable/under_smile_image" 
       android:layout_column="2" 
       android:layout_row="2"/> 
     <ImageView 
       android:layout_gravity="center" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:src="@drawable/under_smile_image" 
       android:layout_column="3" 
       android:layout_row="2"/> 
     <ImageView 
       android:layout_gravity="center" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:src="@drawable/under_smile_image" 
       android:layout_column="4" 
       android:layout_row="2"/> 
     <ImageView 
       android:layout_gravity="center" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:src="@drawable/under_smile_image" 
       android:layout_column="5" 
       android:layout_row="2"/> 
    </GridLayout> 
</LinearLayout> 

И здесь вы можете увидеть, что все улыбки не на дисплее телефона. Что я делаю неправильно? Также мне нужна эта кнопка, которая не масштабирует изображения, которые я помещал в фон.

Wrong layout

ответ

0

Меняйте GridView в match_parent

<GridLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:numColumns="5"> 

На самом деле, я хотел бы посмотреть на что делает ImageViews фиксированного размера, так что все они поместились на экране соответствующим образом.

Смежные вопросы