为什么 textView21.SetLeftTopRightBottom(1,200,45, 275) 不改变 textview 的大小?
为什么 textView21.SetLeftTopRightBottom(1,200,45, 275) 不更改文本视图的大小?
<TextView
android:id="@+id/textView21_id"
android:layout_width="60dp"
android:layout_height="wrap_content"
android:layout_x="22dp"
android:layout_y="105dp"
android:height="50dp"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text=""
android:textSize="30sp"
android:textColor="#000000"
android:background="#9999cc"
android:singleLine="false"/>
这是activity_main.xml 片段。有什么东西可以覆盖 SetLeftTopRightBottom 吗?
我仍在尝试让两个不同但普通的手机(手机)显示相同的视图。 两部手机中同一应用程序的图片
您可以看到左侧图片显示在灰色'下方6:' 文本视图,包括“Go”文本视图和所有右侧单词中第 5 个字母的文本视图区域,而另一张图片则没有。
我已经弄清楚如何获取每部手机的显示指标,
var metrics = Resources.DisplayMetrics;
gnumWidthDp = ConvertPixelsToDp(metrics.WidthPixels);
gnumHeightDp = ConvertPixelsToDp(metrics.HeightPixels);
我认为执行 SetLeftTopRightBottom 操作并将每个文本视图设置在正确的位置会很容易。
请问你能告诉我我错过了什么吗?谢谢大家。
Why doesn't textView21.SetLeftTopRightBottom(1,200,45, 275) change the size of a textview?
<TextView
android:id="@+id/textView21_id"
android:layout_width="60dp"
android:layout_height="wrap_content"
android:layout_x="22dp"
android:layout_y="105dp"
android:height="50dp"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text=""
android:textSize="30sp"
android:textColor="#000000"
android:background="#9999cc"
android:singleLine="false"/>
There's the activity_main.xml snippet. Is there something there which overrides the SetLeftTopRightBottom?
I am still trying to get two different but ordinary mobile phones (cell phones) to display a view the same.
pic of same app in two phones
You can see the left hand pic shows to below the grey '6:' textview and includes the 'Go' textview and all the right hand 5th-letter-in-the-word textview areas whereas the other pic doesn't.
I've figured out how to get each phone's display metrics
var metrics = Resources.DisplayMetrics;
gnumWidthDp = ConvertPixelsToDp(metrics.WidthPixels);
gnumHeightDp = ConvertPixelsToDp(metrics.HeightPixels);
I thought it would be easy to do the SetLeftTopRightBottom thing and set each textview in the right place.
Please can you tell me what I have missed? Thank you all.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在官方文档中,SetLeftTopRightBottom 方法仅用于动画,因为它只是临时将这个位置和大小应用于视图,并且可以随时通过布局更改回来。
更多信息: https:// /developer.android.com/reference/android/view/View#setLeftTopRightBottom(int,%20int,%20int,%20int)
另外, textview21已在xml中得到保证。如果你想动态设置它的大小,你需要使用LayoutParams。例如:
In the official document, SetLeftTopRightBottom method is meant to be used in animations only as it applies this position and size for the view only temporary and it can be changed back at any time by the layout.
More information: https://developer.android.com/reference/android/view/View#setLeftTopRightBottom(int,%20int,%20int,%20int)
In addition, the size of the textview21 had been ensured in the xml. If you want to set the size of it dynamically, you need to use the LayoutParams. Such as: