Ⅰ android studio中layout_width和textview報錯
android:layout_width沒有百分比的設置方法。但可以通過android:layout_weight的方式實現百分比比如
Ⅱ android:layout的width與weight是什麼意思有什麼區別
很簡單啦。width是指這個控制項本身的寬度,而weight是指控制項位於布局(容器)中的寬度位置,一般是百分比。
Ⅲ android按比例布局如何實現
Android LinearLayout weight屬性可以實現
Ⅳ Android開發:為什麼CardView無法使用怎麼解決
拼寫錯誤:
android:layout_width沒有百分比的設置方法。
但可以通過android:layout_weight的方式實現百分比
比如
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="wrap_content"//寬度設為wrap_content自適應
android:layout_height="fill_parent"
android:layout_weight="1" //這里所佔比例是所有LinearLayout下組件自適應後剩餘寬度比例為1/(1+2+3)
android:background="#aa0000"
android:gravity="center"
android:text="1"/>
<TextView
android:layout_width="wrap_content"//寬度設為wrap_content自適應
android:layout_height="fill_parent"
android:layout_weight="2"//這里所佔比例是所有LinearLayout下組件自適應後剩餘寬度比例為2/(1+2+3)
android:background="#00aa00"
android:gravity="center"
android:text="1"/>
<TextView
android:layout_width="wrap_content"//寬度設為wrap_content自適應
android:layout_height="fill_parent"
android:layout_weight="3"//這里所佔比例是所有LinearLayout下組件自適應後剩餘寬度比例為3/(1+2+3)
android:background="#0000aa"
android:gravity="center"
android:text="1"/>
</LinearLayout>
Ⅳ 如何添加android百分比布局支持庫
相信大家都已經對Android API所提供的布局方式非常熟悉了。也許在接觸Android的時候都有過這樣的想法,如果可以按照百分比的方式進行界面布局,這樣適配各種屏幕就簡單多了吧!谷歌正式提供百分比布局支持庫(android-support-percent-lib)。當然了android-percent-support這個庫,基本可以解決上述問題,下面我們將對這個支持庫進行介紹
這個庫提供了:
兩種布局供大家使用:
PercentRelativeLayout、PercentFrameLayout,通過名字就可以看出,這是繼承自FrameLayout和RelativeLayout兩個容器類;
支持的屬性有:
layout_widthPercent、layout_heightPercent、
layout_marginPercent、layout_marginLeftPercent、
layout_marginTopPercent、layout_marginRightPercent、
layout_marginBottomPercent、layout_marginStartPercent、layout_marginEndPercent。
Ⅵ 安卓開發如何設置wight比重
在xml文件裡面設置,一般在線性布局裡面使用。android:layout_weight="1"通過此熟悉設置權重,即所佔比例。比如2個空間,一個android:layout_weight="1",另一個android:layout_weight="2",則前一個比重為1/(1+2)=1/3,另外一個為2/3.
具體可參考這個鏈接http://www.2cto.com/kf/201109/104482.html
Ⅶ Android Studio不能添加百分比布局的依賴,書和AS不一樣,老報錯,怎麼弄急~~~
我正好也在看這本書,這里也遇到同樣的問題,不過仔細對比書上,可以看到書上的定義有:
compile 『com.android.support:appcompat-v7:24.2.1』
compile'com.android.support:percent:24.2.1'
這里其實和大多數遇到問題的同學都會有同一個問題,按照書上直接去添加compile'com.android.support:percent:24.2.1' 這句話會報錯,
java">(24)thanthecompileSdkVersion(28)less...(Ctrl+F1)
Inspectioninfo:,ortoolsandlibraries,thatareincompatible,orcanleadtobugs.iesthatisnotthelatestversion(orinparticular,).Issueid:GradleCompatible
翻一下大概意思是(直接用翻譯工具):
這個支持庫不應該使用與編譯版本(28)不同的版本(24)。(Ctrl + F1)
檢查信息:有些庫或工具與庫的組合不兼容,或可能導致錯誤。這樣的不兼容性之一是編譯的Android支持庫版本不是最新的版本(特別是低於targetSdkVersion的版本)。問題id: GradleCompatible
這里就是說你的版本不一致一個是28一個24,說的就是
implementation 'com.android.support:appcompat-v7:28.0.0'和api 'com.android.support:percent:24.2.1'這兩個後綴要同步,把它改為
implementation'com.android.support:percent:28.0.0'就可以了,只要版本號一樣就可以了,
再來說一下題主第三張截圖的報錯,這個我之前有遇到,那時候覺得是自己無意間動了配置造成的,又不想去花時間搜索答案,就把AS卸載干凈 並把user下的生成的文件也刪掉重裝一遍就好了,不過現在看來網上其它大神有解決的思路可以參照網頁鏈接
最後雖然問題有點久了,但是若以後其他人遇到也好參照一下,哈哈
Ⅷ android layout_width按比例布局問題
用LinearLayout,設置每個子項的weight
Ⅸ android:layout_width 單位有沒有百分比的設置方法
沒有設置方法
線性布局就用權重,設置layout_width="0dp",加個android:layout_weight="1.0"//權重
相對布局設置layout_width="0dp",然後在代碼中通過屏幕寬度設置每個控制項的大小。
可以通過android:layout_weight的方式實現百分比
(9)androidwidth百分比擴展閱讀:
view中的layout_width形容的是本view和父容器的關系;而view中的width是用來描述自己本身的。
android:width 的值,一般是 "100dp" 這樣的數值;
android:layout_width 的值,一般是"fill_parent","wrap_content","match_parent".當然,它也可以像前者一樣,設置數值的。
android:layout_width 其實是可以實現 android:width 的效果的,我覺得這應該是為什麼在 android 實例中看不到有人用 android:width 的原因吧。
帶"layout"的屬性是指整個控制項而言的,是與父控制項之間的關系,如 layout_gravity 在父控制項中的對齊方式, layout_margin 是級別相同的控制項之間的間隙等等;
不帶"layout" 的屬性是指控制項中文本的格式,如gravity是指文本的對齊方式等等,而其中文本的格式又受制約於它的控制項在父控制項中的屬性。
Ⅹ Android布局文件設置TableLayout某一列寬度為屏幕寬度的30%
我給你一個思路吧:
<TableLayout
android:width=0dp;
android:weight=7;/>
<LinearLayout
android:width=0dp;
android:weight=3;/>
這樣就會有一個tablelayout和一個LinearLayout,tablelayout寬度占總寬度的30%,線性布局佔70%
權重做的,具體代碼這樣:
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<TableRow
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@android:color/holo_orange_light" >
</TableRow>
<TableRow
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@android:color/background_light" >
</TableRow>
<TableRow
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3"
android:background="@android:color/darker_gray" >
</TableRow>
<TableRow
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@android:color/holo_blue_bright" >
</TableRow>
<TableRow
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@android:color/holo_green_dark" >
</TableRow>
<TableRow
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@android:color/holo_orange_dark" >
</TableRow>
<TableRow
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@android:color/holo_purple" >
</TableRow>
<TableRow
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@android:color/holo_red_dark" >
</TableRow>
</TableLayout>
實現的效果就是: