Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了android – 将textview垂直于EditText大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
要做的是有一个TextView,右边是一个占用剩余空间的editText. textView应沿editText垂直居中.现在我可以使用linearlayout来做到这一点,但是我更喜欢在relativelayout中进行.

@H_673_7@<RelativeLayout xmlns:android="http://scheR_152_11845@as.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="10dp"> <TextView android:id="@+id/logintext" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Login:" android:paddingRight="20dp" /> <EditText android:id="@+id/login" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_toRightOf="@id/logintext" /> </RelativeLayout>

解决方法

您可以通过使用RelativeLayout为其子项提供的 android:layout_alignBottomandroid:layout_alignTop属性以及TextView的 android:gravity属性来实现您的目标.

这些属性允许您设置视图的底部/顶部边缘以匹配另一个视图的底部/顶部边缘.通过将它们应用于TextView,您可以有效地使TextView与EditText控件的高度匹配.然后,使用gravity属性,您可以将TextView中心的文本垂直放在TextView控件中.

以下示例应按预期工作:

@H_673_7@<RelativeLayout xmlns:android="http://scheR_152_11845@as.android.com/apk/res/android" xmlns:tools="http://scheR_152_11845@as.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:padding="5dp" > <TextView android:id="@+id/user_name_label" android:text="@String/user_name" android:layout_width="wrap_content" android:layout_height="0dp" android:layout_alignBottom="@+id/user_name_text" android:layout_alignTop="@id/user_name_text" android:layout_marginRight="5dp" android:gravity="center_vertical" /> <EditText android:id="@id/user_name_text" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_alignParentright="true" android:layout_toRightOf="@id/user_name_label" /> </RelativeLayout>

大佬总结

以上是大佬教程为你收集整理的android – 将textview垂直于EditText全部内容,希望文章能够帮你解决android – 将textview垂直于EditText所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。