导航:首页 > 操作系统 > androidwidth百分比

androidwidth百分比

发布时间:2022-08-10 09:33:18

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>

实现的效果就是:

阅读全文

与androidwidth百分比相关的资料

热点内容
情歌恋曲 电影 浏览:264
法国高分电影有哪些预言者 浏览:968
命令怎么学 浏览:818
李采谭的影片 浏览:679
吃屎的电影叫什么头像恶心 浏览:790
《新妈妈的目的》演员表 浏览:188
何家驹电影大全 浏览:941
雷军的编程代码 浏览:452
怎么把wps转换为pdf格式的文件 浏览:55
天津网关服务器云空间 浏览:689
韩国电影交换的的一天BH的女演员 浏览:552
腐剧网耽美电影 浏览:910
台湾绝版电影一箭双雕 浏览:883
训诫文sp管教mf 浏览:932
搜索软件如何加密 浏览:905
车载高清视频下载的网站 浏览:656
吃哺乳妈妈奶水小说 浏览:960
进栈算法代码 浏览:786
抗日战争电影100部老电影 浏览:139
重生为杨过 浏览:579