设为首页 加入收藏

TOP

Android开发教程:取得布局中指定控件的宽高
2014-11-24 08:12:44 来源: 作者: 【 】 浏览:0
Tags:Android 开发 教程 取得 布局 指定 控件

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;


public class GetWH extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
View view = getLayoutInflater().inflate(R.layout.main, null);
Button button = (Button) view.findViewById(R.id.button2);
int width = button.getLayoutParams().width;
int height = button.getLayoutParams().height;
Log.i("System.out", width + "-----" + height);
}
}



< xml version="1.0" encoding="utf-8" >
android:id="@+id/linearlayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
android:id="@+id/button2"
android:layout_width="80px"
android:layout_height="80dp"
android:text="Button" />


从结果中大家可以看出些什么呢?大笑


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Linux对电平触发与沿触发中断的区.. 下一篇Android开发教程:动态添加控件

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·Linux_百度百科 (2025-12-26 12:51:52)
·Shell 流程控制 | 菜 (2025-12-26 12:51:49)
·TCP/UDP协议_百度百科 (2025-12-26 12:20:11)
·什么是TCP和UDP协议 (2025-12-26 12:20:09)
·TCP和UDP详解 (非常 (2025-12-26 12:20:06)