0

我的应用程序中有两个ImageView,一个TextView和一个Gallery,并希望我的布局如下所示。

............................................-.
<ImageView>|     <TextView>      |<ImageView>|
..............................................
|                                            |
|                  Gallery                   |
|                                            |
|............................................|

我有一个表格布局,几乎得到了如上所示的设计,除了当文本长度很小时ImageView,屏幕右端的位置会继续移动。无论文本大小如何,我都希望ImageView屏幕左端和右端的 ' 被固定。

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

    <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
         android:layout_height="wrap_content" 
         android:layout_width="wrap_content">

         <TableRow>
              <ImageView xmlns:android="http://schemas.android.com/apk/res/android"
                   android:id="@+id/imageL"
                   android:layout_width="fill_parent"
                   android:layout_height="fill_parent"  
                   android:layout_weight="1"
                   android:minHeight="30px"
                   android:minWidth="30px" />

              <TextView xmlns:android="http://schemas.android.com/apk/res/android"
                   android:id="@+id/title"
                   android:paddingLeft="10px"
                   android:layout_width="wrap_content"
                   android:layout_height="wrap_content" 
                   android:layout_weight="3"
                   android:layout_gravity="center"
                   android:minHeight="30px"
                   android:minWidth="30px" />

               <ImageView xmlns:android="http://schemas.android.com/apk/res/android"
                   android:id="@+id/imageR"
                   android:paddingLeft="10px"
                   android:layout_width="fill_parent"
                   android:layout_height="fill_parent"
                   android:layout_weight="1"
                   android:minHeight="30px"
                   android:minWidth="30px" />
          </TableRow> 
    </TableLayout>

    <Gallery xmlns:android="http://schemas.android.com/apk/res/android"
         android:id="@+id/gallery"
         android:layout_width="fill_parent"
         android:layout_height="wrap_content" />
</LinearLayout>
4

3 回答 3

0

类似的东西。如果要为 img 制作静态宽度和高度,可以在 android:layout_width 和 android:layout_height 中进行设置

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
    <ImageView 
    android:id="@+id/firstImage"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:src="@drawable/icon"
    />
    <TextView 
    android:id="@+id/someText"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_toLeftOf="@+id/secondImage"
    android:layout_toRightOf="@+id/firstImage"
    android:text="some mega text."
    android:gravity="center_horizontal"
    />
    <ImageView 
    android:id="@+id/secondImage"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:src="@drawable/icon"
    />

</RelativeLayout>
于 2011-02-15T12:27:04.213 回答
0

对所有三个项目使用相同的权重,应该解决问题。

android:layout_weight="1"

所有 3 将占据相同的区域。

于 2011-02-15T12:28:47.590 回答
0

将此添加到您的 TableLayout-tag 中:

android:shrinkcolumns="0,2" android:stretchColumns="1"

此外,您可能希望将 layout_width 更改为 fill_parent,因为这将允许中间列拉伸。

于 2011-02-15T14:19:06.353 回答