自定義viewgroup時,報錯提示:沒有找到屬性rightpadding的資源標識符
xml文件中的引用:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
? ? xmlns:tools="http://schemas.android.com/tools"
? ? xmlns:hyman="http://schemas.android.com/apk/res/com.imooc.slidingmenu"
? ? android:layout_width="match_parent"
? ? android:layout_height="match_parent" >
已指明屬性的用法:
public SlidingMenu(Context context, AttributeSet attrs, int defStyle) {
super(context,attrs,defStyle);
TypedArray a = context.getTheme().obtainStyledAttributes(attrs,R.styleable.SlidingMenu, defStyle, 0);
int n = a.getIndexCount();
for (int i = 0; i < n; i++)
{
int attr = a.getIndex(i);
switch (attr)
{
case R.styleable.SlidingMenu_rightPadding:
mMenuRightPadding = a.getDimensionPixelSize(attr,(int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 50, context.getResources().getDisplayMetrics()));
break;
}
}
attr.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
? ? <attr name="rightPadding" format="dimension"></attr>
? ? <declare-styleable name="SlidingMenu">
? ? ? ? <attr name="rightPadding"></attr>
? ? </declare-styleable>
</resources>
2015-01-08
你好,從你貼出的代碼,看起來沒有問題,建議把項目clean,或者close Project 在 open Project 嘗試下。
2015-01-08
mainfest中的包名也是正確的
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
? ? package="com.immoc.slidingmenu"
? ? android:versionCode="1"
? ? android:versionName="1.0" >
? ? <uses-sdk
? ? ? ? android:minSdkVersion="8"
? ? ? ? android:targetSdkVersion="21" />
? ? <application
? ? ? ? android:allowBackup="true"
? ? ? ? android:icon="@drawable/ic_launcher"
? ? ? ? android:label="@string/app_name"
? ? ? ? android:theme="@style/Theme.AppCompat.Light.NoActionBar" >
? ? ? ? <activity
? ? ? ? ? ? android:name="com.imooc.slidingmenu.MainActivity"
? ? ? ? ? ? android:label="@string/app_name" >
? ? ? ? ? ? <intent-filter>
? ? ? ? ? ? ? ? <action android:name="android.intent.action.MAIN" />
? ? ? ? ? ? ? ? <category android:name="android.intent.category.LAUNCHER" />
? ? ? ? ? ? </intent-filter>
? ? ? ? </activity>
? ? </application>
</manifest>