
ActualWidth试试,double值
>var image=new Image();
imagesrc=//你的背景的src;
var divelement = documentgetElementById(你的div的id);
divelementstyleheight=(imageheightdivelementoffsetWidth)/imagewidth + "px";
几个需要注意的地方是imagesrc=xxx后需要等待直到下载完成。但是如果这个脚本是在你的div已经初始化好之后调用的话,那么已经被下载过了,所以直接进行后面的就好。另外以styleheight来设置高度的话后面需要加单位,比如px
android中的控件如果在xml布局文件中把控件的layout_width和layout_height写成固定值了,好像就不能再在程序中更改该控件的高度和宽度了,不知哪位大侠有何良策可以指教一二,如
xml文件内容如下:
<LinearLayout
android:id="@id/dialog_bottom_neutral"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="10"
android:gravity="center"<Buttonandroid:id="@id/dialog_bottom_neutral_button"
android:layout_width="800dip"
android:layout_height="280dip"
android:background="@drawable/dlg_button"
android:gravity="center"
android:singleLine="true"
android:text="mid"
android:textColor="@drawable/dlg_button_text_color"
android:textSize="140sp" /
小弟在程序中使用buttonwidth和buttonheight设置没用,用LayoutParmas设置也没用
web动态页面大小非常有用:
在开发App端的网页时,要适配iphone、ipad、ipod、安卓等各种机型,一般是直接使用em、px转em、界面缩放。
下面是具体的自适应实现方式的尝试~
方案一:设置tranform/scale
首先设置内容固定宽度、自动高度 ,
通过获取窗口的宽度与固定宽度相除,获得缩放比例
在html层,添加一段script:
添加一段设置zoom值的函数:
注:
以上也可以直接写script,我上面返回一段html是因为项目是通过服务端渲染的。
样式的设置必须在界面加载之前,否则会因界面显示变更出现闪现问题。
因为添加了服务端渲染,所以无法在界面一开始初始时,无法获取window、document等对象。而上面html的注入,对服务端渲染机制的一个黑科技~
上面的方案完成后,看看效果。
你这样的写的话 不先赋值给thumbnail统一的高度的话恐怕页面会显得参差不齐而不是你想的4块模块平均撑开页面,还有你是把写进div你当背景,那就不需要js来处理这个问题。
<style>#thumbnailbox{position: absolute;left:0;top:0;width:100%;height:100%;}
#thumbnailbox a{width:50%;height:50%;display:block;position:absolute;left:0;top:0;}
#thumbnailbox abg1{background:url(/images/1jpg) 50% 50% no-repeat;}
#thumbnailbox abg2{left:50%;background:url(/images/2jpg) 50% 50% no-repeat;}
#thumbnailbox abg3{top:50%;background:url(/images/3jpg) 50% 50% no-repeat;}
#thumbnailbox abg4{left:50%;top:50%;background:url(/images/4jpg) 50% 50% no-repeat;}
</style>
<div id="thumbnailbox">
<a href="post_1html" title="缩略图1" class="thumbnail bg1"></a>
<a href="post_1html" title="缩略图1" class="thumbnail bg2"></a>
<a href="post_1html" title="缩略图1" class="thumbnail bg3"></a>
<a href="post_1html" title="缩略图1" class="thumbnail bg4"></a>
</div>
获取屏幕的宽度和高度然后计算出你控件的大小,然后只进去就行了,,,如果全屏显示就设置LayoutParamsMATCH_PARENT如果自适应就设置LayoutParamsWRAP_CONTENT
int width = getScreenWidth/2;
int height = getScreenHeight/2;
imageView]setLayoutParams(new LayoutParams(width, height));
全屏
imageView]setLayoutParams(new LayoutParams(LayoutParamsMATCH_PARENT, LayoutParamsMATCH_PARENT));
自适应
imageView]setLayoutParams(new LayoutParams(LayoutParamsWRAP_CONTENT, LayoutParamsWRAP_CONTENT));
public int getScreenWidth() {
WindowManager wm = (WindowManager) sInstance
getSystemService(ContextWINDOW_SERVICE);
Display display = wmgetDefaultDisplay();
return displaygetWidth();
}
以上就是关于WPF里当Label的宽度设置为auto时,怎么动态获取Label的宽度全部的内容,包括:WPF里当Label的宽度设置为auto时,怎么动态获取Label的宽度、js获取背景图片宽高比后根据浏览器宽度动态赋值div.style.height、android 如何动态设置控件的宽度和高度等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)