0

我想将四个ImageViews 与 s 一起水平显示TextView。这是我想要制作的屏幕和示例屏幕。我怎样才能做到这一点?

在此处输入图像描述

XML 代码:

 <LinearLayout
  android:orientation="horizontal"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:background="#CCCCCC"
  android:layout_gravity="center"
  >

<ImageView
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
     android:src="@drawable/ic_launcher"
    />
<ImageView
    android:id="@+id/button2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
   android:src="@drawable/ic_launcher"
    />
 <ImageView
    android:id="@+id/button3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/ic_launcher"
    />
    <ImageView
    android:id="@+id/button4"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
   android:src="@drawable/ic_launcher" 
    />
 </LinearLayout>
4

4 回答 4

2

您可以像这样将每个 ImageView/TextView 对包装在 LinearLayout 中:

<LinearLayout
  android:id="@+id/group1"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:orientation="vertical"
  android:gravity="center_horizontal>
  <ImageView
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/ic_launcher"
    />
  <TextView
    android:id="@+id/text1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@strings/my_text" />
</LinearLayout>

编辑:添加重力属性以保持一切一致

于 2013-11-07T10:23:02.600 回答
2

这行得通。我检查了。

  <LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:background="#CCCCCC"
    android:orientation="horizontal" >

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

        <ImageView
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_launcher" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="hai there" />
    </LinearLayout>

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

        <ImageView
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_launcher" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="hai there" />
    </LinearLayout>

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

        <ImageView
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_launcher" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="hai there " />
    </LinearLayout>

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

        <ImageView
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_launcher" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="hai there" />
    </LinearLayout>
</LinearLayout>
于 2013-11-07T10:29:32.243 回答
0

使用 TableRow 并将所有图像放在其中。不要忘记给 android:layout weight=1。

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

<ImageView
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:src="@drawable/ic_launcher" />

<ImageView
    android:id="@+id/button2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:src="@drawable/ic_launcher" />

<ImageView
    android:id="@+id/button3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:src="@drawable/ic_launcher" />

<ImageView
    android:id="@+id/button4"
    android:layout_width="wrap_content"
    android:layout_weight="1"
    android:layout_height="wrap_content"
    android:src="@drawable/ic_launcher" />
</TableRow>
于 2013-11-07T10:24:51.750 回答
0

用这个

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


<ImageView
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
     android:src="@drawable/ic_launcher"
    android:layout_weight=".25f"
    />


<ImageView
    android:id="@+id/button2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
   android:src="@drawable/ic_launcher"
     android:layout_weight=".25f"
    />
 <ImageView
    android:id="@+id/button3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/ic_launcher"
      android:layout_weight=".25f"
    />
    <ImageView
    android:id="@+id/button4"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
   android:src="@drawable/ic_launcher" 
     android:layout_weight=".25f"
    />
 </LinearLayout>
于 2013-11-07T10:27:33.430 回答