android - 按钮文本改变方向或换行

标签 android android-fragments

我有一项 Activity ,我创建了 2 个或更多 fragment 。 当 Activity 最初加载并显示第一个 fragment 时,一切都显示正常,如下图所示。

Buttons display good

如果我再做一个替换 fragment ,按钮文本会变成一个奇怪的布局,如下图所示。 Buttons display bad

我的 Activity 布局xml;

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    tools:context="package.android.incabandroid.ActivityJavas.PalletStatusActivity">

    <TextView android:id="@+id/lblpodstats" android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:layout_centerHorizontal="true"
        android:text="TextView" />

    <TableLayout android:id="@+id/butLinLayout"
        android:layout_width="match_parent" android:layout_height="wrap_content"
        android:layout_alignParentBottom="true" android:orientation="horizontal">
        <TableRow>
            <Button android:id="@+id/btnApplyToAll" style="?android:attr/buttonStyleSmall"
                android:layout_width="0dp" android:layout_height="wrap_content"
                android:layout_weight="1" android:text="Select for all" />

            <Button android:id="@+id/btnViewTc" style="?android:attr/buttonStyleSmall"
                android:layout_width="0dp" android:layout_height="wrap_content"
                android:layout_weight="1" android:text="View TnC's" />
        </TableRow>

        <TableRow>
            <Button android:id="@+id/btnPodStatBack" android:layout_width="0dp"
                android:layout_height="wrap_content" android:layout_weight="1"
                android:text="Back" />
            <Button android:id="@+id/btnPodStatNext" android:layout_width="0dp"
                android:layout_height="wrap_content" android:layout_gravity="right"
                android:layout_weight="1" android:text="Next" />
        </TableRow>
    </TableLayout>
    <ScrollView android:id="@+id/scrollStatsList"
        android:layout_width="match_parent" android:layout_height="wrap_content"
        android:layout_below="@id/lblpodstats" android:layout_above="@id/butLinLayout">

        <LinearLayout android:id="@+id/palletStatusLinLayout"
            android:layout_width="match_parent" android:layout_height="wrap_content"
            android:orientation="vertical">
        </LinearLayout>
    </ScrollView>


</RelativeLayout>

我所做的就是用新 fragment 替换 palletStatusLinLayout。 如果我在其中一个按钮上执行 setText,当它们显示怪异时,按钮会更改并正确显示,与第一张图片相同。

非常感谢任何帮助,谢谢。

最佳答案

尝试使用 LinearLayouts 而不是 TableLayout,我总是这样做。

将 TableLayout 替换为:

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

和 TableRow 用于:

<LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"> </LinearLayout>

关于android - 按钮文本改变方向或换行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29846512/

相关文章:

android - 如何从另一个模块调用layout xml

从滑动菜单进行 Android 导航 - fragment 还是 Activity ?

android - 检查类是 fragment 还是 Activity

java - 匿名 Runnable 中使用的最终 int 参数

java - 如何使用intent settype搜索自定义文件扩展名的文本文件

android - 同时启动多个 ViewPropertyAnimator

java - 如何将大量可绘制图像加载到 fragment ListView中?

android - Google Pay 不显示总价或 displayItems

android - 一个 Physical Web Beacon 可以写入多少个 URL?

android - 我可以在编辑文本中使用 Google Places API 吗?