android - layout_widthPercent加載dependencies后還是不能使用,是什么原因?
問題描述
為什么添加依賴后,還是不能使用layout_widthPercent/layout_heightPercent?依賴:
dependencies { compile fileTree(dir: ’libs’, include: [’*.jar’]) androidTestCompile(’com.android.support.test.espresso:espresso-core:2.2.2’, {exclude group: ’com.android.support’, module: ’support-annotations’ }) compile ’com.android.support:percent:24.2.1’ compile ’com.android.support:appcompat-v7:24.2.1’ testCompile ’junit:junit:4.12’}
使用layout_widthPercent
<?xml version='1.0' encoding='utf-8'?><android.support.percent.PercentFrameLayout xmlns:android='http://schemas.android.com/apk/res/android' xmlns:app='http://schemas.android.com/apk/res-auto' android:layout_width='match_parent' android:layout_height='match_parent'> <Buttonandroid: android:text='Button1'android:layout_gravity='left|top'android:layout_widthPercent='50%'android:layout_heightPercent='50%'/></android.support.percent.PercentFrameLayout>
告警:
No resource identifier found for attribute ’layout_widthPercent’ in package ’android’
問題解答
回答1:謝邀. 沒有使用過 android.support.percent.PercentFrameLayout , 但是從 package 名字就大概知道它是support提供的, 非原生環(huán)境中所支持的Layout. 所以xml代碼應(yīng)該如下:
<?xml version='1.0' encoding='utf-8'?><android.support.percent.PercentFrameLayout xmlns:android='http://schemas.android.com/apk/res/android' xmlns:appCompat='http://schemas.android.com/apk/res-auto' android:layout_width='match_parent' android:layout_height='match_parent'> <Buttonandroid: android:text='Button1'android:layout_gravity='left|top'appCompat:layout_widthPercent='50%'appCompat:layout_heightPercent='50%'/></android.support.percent.PercentFrameLayout>
注意 appCompat 的定義和引用.最后說一點, 但凡在代碼里或者layout-xml能引用的Layout(or View), 都是可以正常使用的. 如果報錯, 那就是用法用錯了.
p.s. 如果答錯, 請直接踩這個回答吧(因為我沒具體使用過該PercentFrameLayout).
相關(guān)文章:
1. java - 請問在main方法中寫成對象名.屬性()并賦值,與直接參參數(shù)賦值輸錯誤是什么原因?2. mysql 創(chuàng)建root 用戶出錯,這是什么原因?mysql 中也沒有root用戶3. 請問一下,圖片上傳成功,但是后臺對應(yīng)文件夾里面卻沒有圖片,這是什么原因?(已部署到服務(wù)器)4. python - 文件里有這個文檔,但是終端說找不到,是什么原因?5. node.js - node socket出錯,這是什么原因?另外我想設(shè)置連接超時,怎么寫呢?6. node.js - nodejs和前端JavaScript 字符串處理結(jié)果不一樣是什么原因?7. CSS 控制HTML頁面高度會導致抖動,是什么原因?8. Android Studio 中 xUtils 3.0 替換 2.0 的時候總報找不到 jar 包是什么原因?9. python - 使用pyhook監(jiān)聽按鍵,刪除指定字符,但第二次運行會報錯,這是什么原因?10. 用python3的smtplib庫發(fā)郵件一直返回無法發(fā)送郵件提示,是什么原因?
