我有一项 Activity ,我创建了 2 个或更多 fragment 。 当 Activity 最初加载并显示第一个 fragment 时,一切都显示正常,如下图所示。
如果我再做一个替换 fragment ,按钮文本会变成一个奇怪的布局,如下图所示。
我的 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/