【问题标题】:TableLayout alignment with iconTableLayout 与图标对齐
【发布时间】:2012-08-21 08:42:36
【问题描述】:

这是我的 XML。 我想将图标向左对齐,文本应该出现在图标旁边,并留有一些空间,就像你在其他地方看到的那样。但是文本显示在中心。 (或右对齐到第二列,在两列布局中)

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

  <TableLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:background="@android:color/white"
    android:layout_margin="5dp"
    android:stretchColumns="2"  
    android:layout_height="wrap_content">

       <TableRow
        android:id="@+id/events_header"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@android:drawable/list_selector_background"
        android:clickable="true"
        android:padding="5dip">
              <ImageView android:id="@+id/ImageView02" 
                  android:src="@drawable/event_icon"
                      android:layout_width="wrap_content"
          android:layout_height="wrap_content"
                  android:layout_gravity="center_vertical|left"
                  android:layout_margin="5dp">
              </ImageView>
              <TextView
                android:id="@+id/text1"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="View Events"
                android:layout_gravity="left"
                android:textSize="21dp"
                android:textStyle="bold"
                android:background="@android:color/black"
                android:textColor="@android:color/white" />
         </TableRow>
        </TableLayout>
   </ScrollView>

这是它的显示方式:

    [  *             View Events        ]
  • 是图标。我想这样显示。

    [  *  View Events                   ]
    

【问题讨论】:

  • 那个图标的大小是多少?很有可能它被按比例缩小而没有实际包裹结果的界限。尝试将android:adjustViewBounds="true" 添加到ImageView
  • 没用 :-( 尺寸为 16X16px。

标签: android icons alignment tablelayout


【解决方案1】:

尝试将android:stretchColumns="2" 更改为android:stretchColumns="1",因为列索引以0 开头。因此,如果您只有两列,则第二列位于索引 1

【讨论】:

  • 最初是 1。由于这不起作用,我尝试了 2 来查看它是否改变。布局没有变化。问题依然存在。
  • 只是一个建议:与其为您的图标使用单独的列,为什么不简单地对您的 TextView 使用 left-drawable 呢?这将导致每行少一个视图
  • 你能解释一下吗?也许你能写出来?谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-10-01
  • 1970-01-01
  • 2012-08-24
  • 2012-08-24
  • 1970-01-01
  • 1970-01-01
  • 2022-12-14
相关资源
最近更新 更多