【问题标题】:TextView shrinks TableLayoutTextView 缩小 TableLayout
【发布时间】:2012-07-04 23:58:59
【问题描述】:

我想创建一个简单的旗帜游戏。你得到了国家名称,然后你必须猜出正确的国旗。在我的播放屏幕上,我有一个 TextView 和一个 TableLayout,其中 2 行中有 4 个图像。这些图像的尺寸相同。

问题是:TextView “缩小”了第二个 TableRow,因此图像不再同样大。如果我删除 TextView,一切都很好。

我尝试在 Hierachy Viewer 中调试,它告诉我第二个 TableRow 的属性 mMeasuredHeight 的值非常高(16777526)

我的游戏活动 xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:padding="4dp"
    tools:context=".PlayTimeModeActivity" >

    <TextView
        android:id="@+id/tvFlagName"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        android:text="Hello"
        android:textSize="50dp" />

    <TableLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center_horizontal" >

        <TableRow>

            <ImageView
                android:id="@+id/ivFlag1"
                android:layout_margin="4dp"
                android:contentDescription="@string/cdFlag1" />

            <ImageView
                android:id="@+id/ivFlag2"
                android:layout_margin="4dp"
                android:contentDescription="@string/cdFlag2" />
        </TableRow>

        <TableRow>

            <ImageView
                android:id="@+id/ivFlag3"
                android:layout_margin="4dp"
                android:contentDescription="@string/cdFlag3" />

            <ImageView
                android:id="@+id/ivFlag4"
                android:layout_margin="4dp"
                android:contentDescription="@string/cdFlag4" />
        </TableRow>
    </TableLayout>
</LinearLayout>

您需要更多信息吗?

不知道这样的图片布局能不能做得更好?

编辑: 图片分辨率很高

【问题讨论】:

    标签: android android-layout textview android-tablelayout


    【解决方案1】:

    试试这个:

    使布局的根 (LinearLayout) 具有以下属性 android:layout_width="match_parent"android:layout_height="match_parent"

    将您的TableLayout 设置为android:layout_height="wrap_content"。这将使它在放置文本后占用屏幕上的任何剩余空间,而不是挤压 Hello 文本。

    为每个TableRow 添加android:layout_weight="1"。这将使每一行在TableLayout 中占用均匀的空间。

    对于表中的每个ImageView,设置android:layout_weight="1"。同样,这将为您的每个标志设置均匀的空间。

    标志应该相应地缩放。如果缩放不正确,请在ImageView 中为android:scaleType 尝试不同的值。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-01
      相关资源
      最近更新 更多