Android 在LinearLayout中保持文本视图高度
我在LinearLayout中有两个文本视图。布局方向是水平的。我必须保持两个文本视图的高度相等。但根据文本长度,两者都显示在不同的高度 我试着让同样的文本长度如下所示Android 在LinearLayout中保持文本视图高度,android,Android,我在LinearLayout中有两个文本视图。布局方向是水平的。我必须保持两个文本视图的高度相等。但根据文本长度,两者都显示在不同的高度 我试着让同样的文本长度如下所示 public static String padRight(String s, int n) { return String.format("%1$-" + n + "s", s); } 但身高有点不同。如何解决这个问题?因为文本很长,文本视图越来越大,所以您将文本视图的单行线设置为true,然后它就会工作 在Tex
public static String padRight(String s, int n) {
return String.format("%1$-" + n + "s", s);
}
但身高有点不同。如何解决这个问题?因为文本很长,文本视图越来越大,所以您将文本视图的单行线设置为true,然后它就会工作 在Textview xml中添加此行:--
希望对您有所帮助。因为文本很长,文本视图越来越大,所以您将文本视图的单线设置为true,然后它就会工作 在Textview xml中添加此行:--
希望它对您有所帮助。如果我没有误解您的意思,您希望
TextView
s位于水平方向的LinearLayout
内,并且两者的TextView
高度必须相同
然后使用如下布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/textView1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#B40431"
android:text="text sample\ntext sample\ntext sample\ntext sample\ntext sample\ntext sample\n"
android:gravity="center_vertical"/>
<TextView
android:id="@+id/textView2"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#0000FF"
android:text="text sample\ntext sample\ntext sample"
android:gravity="center_vertical"/>
</LinearLayout>
输出将如下所示:
如果我没有误解您的意思,您希望
TextView
s位于水平方向的LinearLayout
内,并且两个TextView
s必须处于相同的高度
然后使用如下布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/textView1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#B40431"
android:text="text sample\ntext sample\ntext sample\ntext sample\ntext sample\ntext sample\n"
android:gravity="center_vertical"/>
<TextView
android:id="@+id/textView2"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#0000FF"
android:text="text sample\ntext sample\ntext sample"
android:gravity="center_vertical"/>
</LinearLayout>
输出将如下所示:
您可以将textview的布局高度参数固定为某个常量值,你可以在这里发布屏幕截图而不是换行内容吗?请将换行内容添加到具有更高高度的文本视图,对于另一个文本视图,请为匹配父视图并将换行内容添加到线性布局。这会起作用。但我认为这不是一个完美的解决方案。请发布xml布局文件你可以为其修复布局高度参数将textview设置为某个常量值,你可以在这里发布屏幕截图吗?请将内容包装到高度更高的文本视图,对于另一个文本视图,请提供匹配父视图,并将内容包装到线性布局。这会起作用。但我认为这不是一个完美的解决方案。请发布xml布局文件谢谢你的回复。我已经修复了谢谢你的回复。我已经确定了。谢谢你的回答。如果你有帮助解决你的问题,如果我使用单行的话,就不需要考虑TeXVIEW HigITH。你已经回答了我的问题。所以我不得不发感谢信。爱琴海的答案是准确的。但在看到他的答案之前,我已经解决了这个问题。但答案是正确的。所以我接受了他的回答。接受和投票是没有关系的。谢谢你的回答,接受并投票赞成答案,如果它有助于解决你的问题。如果我使用单行,就不需要考虑TeXVIEW HigIt。你已经回答了我的问题。所以我不得不发感谢信。爱琴海的答案是准确的。但在看到他的答案之前,我已经解决了这个问题。但答案是正确的。所以我不得不接受他的答案。接受和投票都没关系。。。。