我有我的应用程序的某些部分的相对布局,由一个复选框,一个按钮,一些文本和另一个按钮组成(请参见第一个截图,例如:[5分钟]屏幕关闭后[除外])。相对布局中的按钮被TextView推下屏幕
问题在于其他语言,最后一个按钮左侧的文本可能会更长,推动“除外”按钮稍微或完全脱离屏幕。我还能怎么做,以便按钮(连同文本)绕回到下一行?现在只有文字。下面是代码:
<RelativeLayout
android:id="@+id/layout_after_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp">
<Button
android:id="@+id/button_set_time_turn_off"
android:layout_width="wrap_content"
android:layout_height="35sp"
android:paddingTop="0dp"
android:paddingBottom="0dp"
style="?android:attr/buttonStyleSmall"
android:layout_centerVertical="true"
android:textSize="16sp"/>
<TextView
android:id="@+id/textView_data_check_minutes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:layout_marginStart="3dp"
android:layout_toRightOf="@+id/button_set_time_turn_off"
android:layout_toEndOf="@+id/button_set_time_turn_off"
android:layout_centerVertical="true"
android:textSize="16sp"
android:textColor="@android:color/primary_text_dark"
android:text="@string/text_disable_after_time" />
<Button
android:id="@+id/button_set_disable_exceptions"
android:layout_width="wrap_content"
android:layout_height="35sp"
android:paddingTop="0dp"
android:paddingBottom="0dp"
android:layout_toRightOf="@+id/textView_data_check_minutes"
android:layout_toEndOf="@+id/textView_data_check_minutes"
style="?android:attr/buttonStyleSmall"
android:layout_centerVertical="true"
android:text="@string/button_disable_except"
android:textSize="16sp"/>
</RelativeLayout>
"except" button pushed off screen http://i60.tinypic.com/214zj3t.png
感谢您的建议@codeMagic。它并不完全符合我想要的,即将文本AND按钮推到下一行,但它确实有效。 textView成为多行,按钮保持原位。我不得不使按钮的重量0.00000001和textView 1的重量,否则按钮被挤压。我不确定为什么权重看起来落后。我会稍等一下,看看是否有人可以想出一种方法来处理文本,最后一个按钮将换行到下一行,否则我会将其标记为正确。 – Flyview 2014-09-20 13:06:28
其实更好的是,我将内部textView的权重设置为1,并且不对按钮设置权重(默认值为0),但在按钮上使用wrap_content作为宽度,并且它完美地工作! – Flyview 2015-04-17 17:12:23