从样式加载这些属性时,一个或多个布局缺少布局高度和布局宽度错误

时间:2018-12-25 13:42:38

标签: android

我正在android studio中编写一个应用程序,其中TextViewsid的所有属性都相同。因此,我在text中声明了一种样式,如下所示:

style.xml

在我的<style name="thirdTextView" parent="TextAppearance.AppCompat"> <item name="android:layout_width">wrap_content</item> <item name="android:layout_height">wrap_content</item> <item name="android:textColor">@color/black</item> <item name="android:layout_gravity">center_vertical</item> </style> 中,我使用了以下样式:

activity_main.xml

但是我看不到布局的预览,但出现此错误:

<TextView
                style="@style/thirdTextView"
                android:text="@string/questionWeight"/>

如何解决这个问题?

1 个答案:

答案 0 :(得分:2)

将您的TextViews更改为此;

<TextView
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   style="@style/thirdTextView"
   android:text="@string/questionWeight"/>

布局文件中的每个小部件都需要height和width属性。希望这会有所帮助。