2013-04-17 2 views
0

Я не могу понять, как должен выглядеть мой макет. У меня есть фрагмент. Внутри него у меня есть scrollView (так как я хочу поддерживать оба орриентации), внутри ScrollView я хотел бы иметь четыре изображения равномерно распределенных (например, это http://numberexplosion.com/wp/wp-content/uploads/2012/04/square-4.gif). Но я просто не могу понять, как это сделать, я пробовал относительные, линейные, табличные вычисления, но не могу получить такой вид: /.Фрагмент с четырьмя изображениями макета

Мой текущий макет:

<?xml version="1.0" encoding="utf-8"?> 
   <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
       android:id="@+id/scrollView1" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" > 

       <TableLayout 
           android:layout_width="fill_parent" 
           android:layout_height="match_parent" 
           android:gravity="center_vertical|center_horizontal" > 

           <TableRow 
               android:id="@+id/tableRow1" 
               android:layout_width="wrap_content" 
               android:layout_height="wrap_content" 
               android:gravity="center_horizontal" > 

               <ImageView 
                   android:id="@+id/imageView1" 
                   android:layout_width="150dp" 
                   android:layout_height="150dp" /> 

               <ImageView 
                   android:id="@+id/ImageVieww2" 
                   android:layout_width="150dp" 
                   android:layout_height="150dp" /> 

           </TableRow> 

           <TableRow 
               android:id="@+id/tableRow2" 
               android:layout_width="wrap_content" 
               android:layout_height="wrap_content" 
               android:gravity="center_horizontal" > 

               <ImageView 
                   android:id="@+id/ImageVieww3" 
                   android:layout_width="150dp" 
                   android:layout_height="150dp" /> 

               <ImageView 
                   android:id="@+id/ImageVieww4" 
                   android:layout_width="150dp" 
                   android:layout_height="150dp" /> 

           </TableRow> 

           <TableRow 
               android:id="@+id/tableRow3" 
               android:layout_width="fill_parent" 
               android:layout_height="wrap_content" > 
           </TableRow> 

       </TableLayout> 

   </ScrollView> 

Этот макет выглядит почти как я хочу, чтобы это было, но размер изображения только 150dp, а не заполняя весь экран в некоторых случаях. Мои источники imageView разные, но я хотел бы, чтобы ImageViews заполнил мой фрагмент. Любые идеи, что я делаю неправильно?

ответ

0

Вы можете сделать что-то подобное. Я знаю его тяжелый макет, но он решит вашу проблему. Я просто использовал два horizontal Linear layouts в Vertical Linear Layout. Я поместил 2 кнопки в каждом horizontal linear layout с weight 1.

Layout VerticalLayout Horizontal

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:orientation="horizontal" > 

     <ImageView 
      android:id="@+id/ImageView1" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_margin="5dp" 
      android:layout_weight="1" 
      android:scaleType="fitXY" 
      android:src="@drawable/no_image" /> 

     <ImageView 
      android:id="@+id/ImageView1" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_margin="5dp" 
      android:layout_weight="1" 
      android:scaleType="fitXY" 
      android:src="@drawable/no_image" /> 

    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:orientation="horizontal" > 

     <ImageView 
      android:id="@+id/ImageView1" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_margin="5dp" 
      android:layout_weight="1" 
      android:scaleType="fitXY" 
      android:src="@drawable/no_image" /> 

     <ImageView 
      android:id="@+id/ImageView1" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_margin="5dp" 
      android:layout_weight="1" 
      android:scaleType="fitXY" 
      android:src="@drawable/no_image" /> 

    </LinearLayout> 

</LinearLayout> 
+0

Это делает работу со статическими кнопками. Но у меня есть ImageViews, в котором я загружаю свои изображения, и после загрузки изображение искажается:/ – Datenshi

+0

Я немного изменил код макета. Надеюсь, это поможет вам. –

0

Довольно хорошее решение состоит в использовании LinearLayout, содержащем 2 LinearLayouts, каждый из которых содержит 2 Views. Хитрость заключается в использовании layout_width/layout_height от 0dp и layout_weight детей (2 LinearLayouts и 4 Views).

Вы также можете попробовать GridLayout (не GridView), который можно приобрести на Android 4.0 (http://developer.android.com/reference/android/widget/GridLayout.html) и с 2.1 в support-library-v7.