首页 > 解决方案 > 无法使布局宽度与我在 XML 上的文本相同

问题描述

我已经开始学习 xml,虽然我使用线性布局并将其 layout_width 设置为 wrap_content,并且还使用我的文本视图的布局宽度作为 wrap_content,但它覆盖了我的屏幕的整个宽度(宽度方向)。

注意:- 仅当我选择垂直方向时才会发生这种情况。有什么我想念的吗?

<LinearLayout
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:background="#D2B48C"
   android:orientation="vertical">

   <TextView
       android:text="sahil"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:background="#DC143C"/> 
</LinearLayout>

以上是我的代码。

这是图像:- 我上面编写的代码的xml结果

标签: android

解决方案


在此处输入图像描述

正如我所看到的,您的 XML 代码结果和TextView宽度似乎是什么wrap_content。您最好也分享您的屏幕截图,以便我可以提供帮助。


推荐阅读