Покажите 4 картинки посередине - PullRequest
0 голосов
/ 24 октября 2011

Hy!

Я хочу иметь такой макет:

enter image description here

Проблема в том, что я не знаю, что использовать:

  • Gridview?
  • TableLayout
  • LinearLayout с PictureViews?

Картинки должны быть ориентированы в середине экрана (по горизонтали и вертикали)

Пожалуйста, добавьте пример кода в ваши ответы.

ТНХ

Ответы [ 2 ]

1 голос
/ 24 октября 2011

один способ может сделать этот тип макета

<?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:orientation="vertical" android:gravity="center_horizontal|center_vertical">
    <LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content">
        <ImageView android:layout_width="150dp" android:layout_height="150dp"
            android:layout_weight="1" android:background="@drawable/bg_img"
            android:layout_margin="5dp"/>
        <ImageView android:layout_width="150dp" android:layout_height="150dp"
            android:layout_weight="1" android:background="@drawable/bg_img"
            android:layout_margin="5dp"/>
    </LinearLayout>
    <LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content">
        <ImageView android:layout_width="150dp" android:layout_height="150dp"
            android:layout_weight="1" android:background="@drawable/bg_img"
            android:layout_margin="5dp"/>
        <ImageView android:layout_width="150dp" android:layout_height="150dp"
            android:layout_weight="1" android:background="@drawable/bg_img"
            android:layout_margin="5dp"/>
    </LinearLayout>
</LinearLayout>

я использовал загрузку этого изображения отсюда, изображение слишком большое, но это был тест, только вы можете использовать ваши изображения, просто замените фоновый src в imageview вкаждый или согласно вашему требованию.

enter image description here

и вы получите результат, подобный этому

enter image description here

0 голосов
/ 24 октября 2011

Пожалуйста, используйте ниже linearlayout с Imageview .. Главный трюк - горячий вес использования в linearlayout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <LinearLayout android:id="@+id/linearLayout1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1">
        <ImageView android:id="@+id/imageView1" android:layout_width="fill_parent" android:layout_weight="1" android:layout_height="fill_parent" android:background="@drawable/icon"></ImageView>
        <ImageView android:id="@+id/imageView2" android:layout_weight="1" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/icon"></ImageView>
    </LinearLayout>
    <LinearLayout android:id="@+id/linearLayout2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1">
        <ImageView android:id="@+id/imageView3" android:layout_width="fill_parent" android:layout_weight="1" android:layout_height="fill_parent" android:background="@drawable/icon"></ImageView>
        <ImageView android:id="@+id/imageView4" android:layout_width="fill_parent" android:layout_weight="1" android:layout_height="fill_parent" android:background="@drawable/icon"></ImageView>
    </LinearLayout>
</LinearLayout>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...