<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/off_background">
<ImageView
android:id="@+id/bottom_layer"
android:src="@drawable/handle"/>
<ImageView
android:id="@+id/upper_layer"
android:src="@drawable/switch_v"/>
</FrameLayout>
無論何時執行該代碼:二進制XML文件行#7:您必須提供layout_width屬性
inflater.inflate(R.layout.settings_switch, this);
我得到這個錯誤:
10-29 13:27:00.090: E/AndroidRuntime(22364): Caused by: java.lang.RuntimeException: Binary XML file line #7: You must supply a layout_width attribute.
怎麼會這樣?
我有
android:layout_width="match_parent"
android:layout_height="match_parent"
你會發現這個錯誤的另一種情況是:尺寸在dimens.xml爲sw720dp定義,但它不是對設備的定義比sw720dp低,你用這個捫VAR設置layout_width,它會墜毀在更小的設備比sw720dp –