❶ 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>
实现的效果就是:
❷ 在安卓手机端 容器没有定义固定宽, 使用viewport 后就缩成一半了
可能是你加的不对,参考我得写法:
<metaname="viewport"content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
<metaname="apple-mobile-web-app-capable"content="yes"/>
<metaname="apple-mobile-web-app-status-bar-style"content="black-translucent"/>
<metaname="format-detection"content="telephone=yes"/>
<metaname="msapplication-tap-highlight"content="no"/>
你应该是做响应式布局的吧,这里有一篇响应式布局的示例,文章比较长不再全文贴出,参考:http://www.51xuediannao.com/html+css/htmlcssjq/704.html
❸ 不同版本的android如何控制对话框宽度
这个是屏幕适配的问题吧。
屏幕宽度不一样,就算用dp,也不能达到好的效果。
如果想达到最佳的效果(比如dialog宽度大概占屏幕宽度的80%),用dp在不同的屏幕上是达不到预期的效果的。
其实有下面这样方法可供参考:
设置match_parent或wrap_content这样的,再设置一下边距,每个屏幕上面都能看吧,如果dialog里面没有把宽度写死的话。
获取设备的宽高的像素,设置一个比值(如上面的80%),把设备的整个宽度,乘以这个比值,在代码里动态进行配置。
如果要用dp来控制,那就建立多个不同的layout-XXX(如layout-lang,layout-ldpi)来适应不同的屏幕吧。
❹ Android TextView宽度和高度固定,怎么根据显示的字符串来计算出字体的尺寸
先获取TextView的padding的值,然后用固定高度或宽度减去padding就是文字所占的空间。
TextView tv = new TextView(this);
int top = tv.getPaddingTop();//有bottom,left,right,
int bottom = tv.getPaddingBottom();
假设固定高度为100,
那么自体高度所占空间应该是 100-(top+bottom)
❺ 怎么限制textview的宽度
android中限制textview的宽度的方法有两种:
1、使用maxlength限制输入的长度
android:maxLines设置文本的最大显示行数,与width或者layout_width结合使用,超出部分自动换行,超出行数将不显示。
2、使用singleLine设置单行显示,并设定layout_width
android:singleLine设置单行显示。如果和layout_width一起使用,当文本不能全部显示时,后面用“…”来表示。如android:text="test_singleLine"
❻ android 代码里怎么设置控件的宽度
在对应的控件中使用android:layout_width标签即可。
android:layout_width标签中可以使用match_parent常量使控件尺寸与其上级组件尺寸相同
可以使用wrap_content使控件尺寸刚好包裹住内容
也可以使用px(像素)、pt(磅)、dp(密度)、sp(可伸缩像素)作为单位,从而设置控件的宽度:
例如:
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="one"
android:layout_gravity="right"/>
❼ android app 界面设计按什么尺寸
android app 界面设计是按720*1280的,切图上可以点9切图做到所有手机的适配。
状态栏、导航栏和主菜单栏,以720*1280的尺寸来设计,那么状态栏的高度应为50px,导航栏的高度96px,主菜单栏的高度96px,因为是开源的系统,这里的数值也只能作为参考。
Android为了区别于IOS,从4.0开始提出了一套HOLO的UI风格设计风格,鼓励将底部的主菜单栏放到导航栏下面,从而避免点击下方材料误点虚拟按键,很多APP的新版中也采用了这一风格。
(7)android固定宽度扩展阅读:
注意事项:
1、通常情况要定位一个Icon只需给出 上/下边距,左/右边距,标注图标距离只需标到可点击范围外
通用型颜色、字体单独标明一份,通用型模块只需单独标明一份,如导航栏。
2、手机可视区域通常为宽度固定,长度超出边界可滑动,所以标注物体宽度时可按比例说明,如果要标注内容上下居中,左右居中,或等比可不标注。
3、当交付的是一张完整图片时,不需做机型适配,只需给高清图(1920*1080)即可,注意进行压缩。
4、若图标在不同页面重复出现,且尺寸相差不大,直接给出最大一份切图,并在圆形图标明尺寸,程序会根据需求缩放。
5、当背景是纯色时只需给出色值,Android使用16进制色值。
参考资料来源:网络-Android
参考资料来源:网络-界面设计
参考资料来源:网络-状态栏
参考资料来源:网络-导航栏
参考资料来源:网络-开源系统
参考资料来源:网络-切图
参考资料来源:网络-UI设计
❽ android 如何动态设置控件的宽度和高度
一、方法
使用getLayoutParams() 和setLayoutParams()方法
二、示例代码
LinearLayout.LayoutParams linearParams = (LinearLayout.LayoutParams) aaa.getLayoutParams();
// 取控件aaa当前的布局参数
linearParams.height = 365; // 当控件的高强制设成365象素
aaa.setLayoutParams(linearParams); // 使设置好的布局参数应用到控件aaa
三、原理
a)getLayoutParams()和setLayoutParams()都是控件基类view的public方法,在外部也可以直接调用。
b)由于LayoutParams一般是在加入容器中设置的,所以容易混淆所指定的布局属性究竟是保存在容器中,还是控件本身的属性,答案是控件本身。但是在设置时还是要注意布局属性与容器种类密切相关。
❾ android ImageView设置宽度
<LinearLayoutxxxx
android:weightSum="2">
<ImageViewxxxx
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
</LinearLayout>
❿ android 动态设置布局宽度
例如设置一个图片宽高 关键代码:
//取控件当前的布局参数
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) imageView.getLayoutParams();
//设置宽度值
params.width = dip2px(MainActivity.this, width);
//设置高度值
params.height = dip2px(MainActivity.this, height);
//使设置好的布局参数应用到控件
imageView.setLayoutParams(params);
1
2
3
4
5
6
7
8
1
2
3
4
5
6
7
8
高度除了可以设置成以上固定的值,也可以设置成wrap_content或match_content
ViewGroup.LayoutParams.WRAP_CONTENT
ViewGroup.LayoutParams.MATCH_PARENT
1
2
1
2
在这里插入图片描述
xml